6708.Towers

Time Limit: 1s Memory Limit: 512MB

You are given $n$ cubes in a certain order, and your task is to build towers using them. Whenever two cubes are one on top of the other, the upper cube must be smaller than the lower cube.

You must process the cubes in the given order. You can always either place the cube on top of an existing tower, or begin a new tower. What is the minimum possible number of towers?

Input Format(From the terminal/stdin)

The first input line contains an integer $n$ : the number of cubes.

The next line contains $n$ integers $k_1,k_2,\ldots,k_n$ : the sizes of the cubes.

  • $1 \le n \le 2 \cdot 10^5$
  • $1 \le k_i \le 10^9$

Output Format(To the terminal/stdout)

Print one integer: the minimum number of towers.

Sample Input

Copy
5
3 8 2 1 5
 \n
 · · · · \n

Sample Output

Copy
2
 \n
Source: CSES, Sorting and Searching, 1073

Submit

请先 登录

© 2025 FAQs