Problem list
Log in
#coci00583 · COCI 2020/2021 Contest 5

Po

Unrated 1.0 s 512 MB

Tinky Winky left a sequence of $n$ zeroes in the Tubbytronic Superdome, and left for a walk with Dipsy. When he came back, he saw that a misdeed has been done. The sequence was changed, and Po was smiling mischeviously in the corner of the room. $Oh$ dear! Po, what have you done?! – asked Tinky Winky in horror. $I$ enhanced the sequence! – replied Po. After cross-examination, it was established that Po did a number of enhancements on the sequence. In every enhancement, she took a segment of a sequence and increased all elements in the segment by some positive integer. Also, every two segments were either disjoint or one was completely contained in other. How many enhancements have you done, Po? – Laa-Laa inquired. $I$ really don’t know! I’m only sure $I$ did the minimum number $of$ enhancements possible $to$ get this sequence! – said Po exhaustedly. Then $it$ surely must $be$ $m$! – proclaimed Noo-Noo. ^{1} What number did Noo-Noo say?

Input

The first line contains an integer $n$ ($1 \le n \le 100,000$), the length of the sequence. The second line contains $n$ nonnegative integers $a_{i}$ ($0 \le a_{i} \le 10^{9}$), the sequence after Po’s enhancements.

Output

Output $m$, the minimum possible number of enhancements.

Constraints

In test cases worth 30 points, it holds $1 \le n \le 1000$.

Example 1

Input
3
2 2 2
Output
1

Example 2

Input
5
2 3 3 3 2
Output
2

Example 3

Input
6
1 2 3 2 1 3
Output
4

Clarification of the second example: Po first increased all elements of the sequence by 2, and then increased the middle three by 1. 1Noo-Noo is the Teletubies’ vacuum cleaner pet.

Source
COCI 2020/2021 Contest 5
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