luogu#P5019. [NOIP 2018 提高组] 铺设道路
[NOIP 2018 提高组] 铺设道路
Background
NOIP 2018 Senior D1T1.
Problem Description
Chunchun is a road engineer responsible for paving a road of length .
The main task of paving is to fill the sunken ground surface. The whole road can be seen as consecutive segments connected end to end. Initially, the sinking depth of the -th segment is .
Each day, Chunchun can choose a continuous interval and fill every segment in this interval, reducing its sinking depth by . When choosing an interval, it must be guaranteed that, before filling, the sinking depth of every segment in the interval is not .
Chunchun wants you to help design a plan that turns the sinking depths of the entire road into in the shortest time.
Input Format
The input file contains two lines. The first line contains an integer , representing the length of the road. The second line contains integers separated by a single space; the -th integer is .
Output Format
The output file contains only one integer, which is the minimum number of days needed to complete the task.
6
4 3 2 5 3 5
9
Hint
【Sample Explanation】
One possible optimal plan is to choose, in order: , , , , , , , , .
【Constraints】
For of the testdata, . For of the testdata, . For of the testdata, , .
Translated by ChatGPT 5