Problem list
Log in
#coci00358 · COCI 2015/2016 Contest 1

Baloni

Gold V 2.0 s 128 MB

There are N balloons floating in the air in a large room, lined up from left to right. Young Perica likes to play with arrows and practice his hunting abilities. He shoots an arrow from the left to the right side of the room from an arbitrary height he chooses. The arrow moves from left to right, at a chosen height H until it finds a balloon. The moment when an arrow touches a balloon, the balloon pops and disappears and the arrow continues its way from left to right at a height decreased by 1. Therefore, if the arrow was moving at height H, after popping the balloon it travels on height $H-1$. Our hero’s goal is to pop all the balloons using as little arrows as possible.

Input

The first line of input contains the integer N ($1 \le N \le 1,000,000$). The second line of input contains an array of N integers Hi. Each integer Hi ($1 \le Hi \le 1,000,000$) is the height at which the i^{th} balloon floats, respectively from left to right.

Output

The first and only line of output must contain the minimal number of times Pero needs to shoot an arrow so that all balloons are popped.

Constraints

In test cases worth 40%, it will hold $N \le 5,000$.

Example 1

Input
5
4 5 2 1 4
Output
2
output

5
output

3

Clarification of the first example: Our hero shoots the arrow at height 5 - which destroys [5, 4, 3], and shoots an arrow at height 2 - which destroys [2, 1].

Source
COCI 2015/2016 Contest 1
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code