Account
GitHubFeedback
Drafts and results saved on this device
Submit on CSES.fi
CSES Problemset/Sorting and Searching

Towers

#1073
Ask AI

Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.

Open Claude Desktop

Time limit:1.00 s
Memory limit:512 MB
Unsolved
Download Tests (.zip)

You are given nn 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

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

The next line contains nn integers k1,k2,…,knk_1,k_2,\ldots,k_n: the sizes of the cubes.

Output

Print one integer: the minimum number of towers.

Constraints
  • 1≤n≤2⋅1051 \le n \le 2 \cdot 10^5
  • 1≤ki≤1091 \le k_i \le 10^9
Sample Test Cases (1)
Example 1ID: sample-1
Input
5
3 8 2 1 5
Expected Output
2
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|1 line, 0 chars
Test Bench
Download .zip
Input (stdin)
5
3 8 2 1 5
Expected Output
2