#P7399. [COCI 2020/2021 #5] Po
[COCI 2020/2021 #5] Po
Description
There is an array of length . In the initial state, all elements are .
In each operation, you may add a positive integer to all numbers in a continuous interval , but it is required that for any two operation intervals, they are either disjoint, or one contains the other.
Find the minimum number of operations needed to transform the original array into the given array .
Input Format
The first line contains an integer .
The second line contains non-negative integers .
Output Format
Output the minimum number of operations required.
3
2 2 2
1
5
2 3 3 3 2
2
6
1 2 3 2 1 3
4
Hint
Explanation for Sample 2
One optimal plan is: add to all elements, then add to the middle three elements.
Constraints
For the testdata worth points, .
For of the testdata, , .
Notes
The score of this problem follows the original COCI settings, with a full score of .
Translated from COCI2020-2021 CONTEST #5 T2 Po.
Translated by ChatGPT 5
京公网安备 11011102002149号