408606: GYM103202 F Kobolds and Catacombs

Memory Limit:1024 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. Kobolds and Catacombstime limit per test2 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard output

Kobolds are rat-like, candle-loving cave folk, digging deep beneath the surface for millennia. Today, they gather together in a queue to explore yet another tunnel in their catacombs!

But just before the glorious movement initiates, they have to arrange themselves in non-descending heights. The shortest is always the leader digging small holes, and the followers swelling it.

The kobolds are hyperactive; they like to move here and there. To make the arrangement easier, they decide to group themselves into consecutive groups first, then reorder in each group.

What's the maximum number of consecutive groups they can be partitioned into, such that after reordering the kobolds in each group in non-descending order, the entire queue is non-descending?

For example, given a queue of kobolds of heights [1, 3, 2, 7, 4], we can group them into three consecutive groups ([1] [3, 2] [7, 4]), such that after reordering each group, the entire queue can be non-descending.

Input

The first line of the input contains a single integer $$$n$$$ $$$(1 \le n \le 10^6)$$$, denoting the number of kobolds.

The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots , a_n$$$ $$$(1 \le a_i \le 10^9)$$$, representing the heights of the kobolds in the queue.

Output

Print a single integer, denoting the maximum number of groups.

ExampleInput
5
1 3 2 7 4
Output
3

加入题单

上一题 下一题 算法标签: