#P51431. [JOI 2021 Final] Growing Vegetables is Fun 4
[JOI 2021 Final] Growing Vegetables is Fun 4
Description
Bitaro likes gardening. He is now growing plants called Biba-herbs in the garden. There are Biba-herbs in the garden, planted in a line from the west to the east. The Biba-herbs are numbered from to from the west to the east. Now, the height of the Biba-herb () is .
Due to the breed improvement, if Bitaro waters a Biba-herb once, then its height increases by . Since he wants to decorate the garden, he will water the Biba-herbs several times so that the following condition is satisfied.
- After Bitaro finishes watering, let be the height of the Biba-herb . Then, there exists an integer () such that holds for every , and holds for every .
However, Bitaro is not good at watering. When he waters Biba-herbs, he can only water consecutive Bibaherbs in an interval. In other words, he chooses integers and () and waters the Biba-herbs .
Bitaro wants to minimize the number of times of watering.
Write a program which, given the number of Biba-herbs and their current heights, calculates the minimum number of times of watering so that the above condition is satisfied.
Input
Read the following data from the standard input. Given values are all integers.
Output
Write one line to the standard output. The output should contain the minimum number of times of watering.
Sample 1
5
3 2 2 3 1
3
The condition is satisfied if Bitaro waters the Biba-herbs three times as follows.
- Let and . Then Bitaro waters the Biba-herbs . The heights of the Biba-herbs become from the west.
- Let and . Then Bitaro waters the Biba-herbs . The heights of the Biba-herbs become from the west.
- Let and . Then Bitaro waters the Biba-herb . The heights of the Biba-herbs become from the west.
It is impossible to satisfy the condition if Bitaro waters the Biba-herbs less than three times. Hence the minimum number of times of watering is .
5
9 7 5 3 1
0
Since the condition is already satisfied, the minimum number of times of watering is .
2
2021 2021
1
The condition is satisfied if Bitaro waters the Biba-herb by choosing and , or he waters the Biba-herb by choosing and .
8
12 2 34 85 4 91 29 85
93
Constraints
- .
- ().
Subtasks
- ( points) .
- ( points) No additional constraints.