#P15980. [PA 2026] 买砾石 / Dostawa żwiru
[PA 2026] 买砾石 / Dostawa żwiru
Problem Description
Bajtazar came across a great opportunity: he can buy a large amount of gravel at a low price. He wants to use this gravel to level a small path in his garden. The path consists of segments, with initial heights . Each time he dumps one truckload of gravel, he can increase the height of one segment of the path by . Bajtazar wants the path not to be too steep: the height difference between any two adjacent segments must not exceed . What is the minimum number of truckloads of gravel Bajtazar needs to buy to achieve his goal?
Input Format
The first line contains two integers and (, ), representing the number of segments of the path and the maximum allowed height difference between adjacent segments.
The second line contains integers (), representing the initial height of each segment.
Output Format
Print one integer: the minimum number of truckloads of gravel required to level the path.
4 2
7 3 0 2
5
Hint
Sample explanation: We can raise the second segment by to height , and raise the third segment by to height . Note that it is not allowed to decrease the height of any segment.
Translated by ChatGPT 5