#P3817. 小A的糖果
小A的糖果
Description
Xiao A has candy boxes; the -th box contains candies.
Each time, Xiao A can eat one candy from one box. He wants to know: to make the sum of candies in any two adjacent boxes no greater than , what is the minimum number of candies he must eat.
Input Format
The first line contains two space-separated integers, the number of boxes and the given parameter .
The second line contains space-separated integers; the -th integer is , the number of candies in the -th box.
Output Format
Output one line with a single integer, the minimum number of candies to eat.
3 3
2 2 2
1
6 1
1 6 1 2 0 4
11
5 9
3 1 4 1 5
0
Hint
Explanation for Sample Input/Output 1
Eating one candy from box 2 suffices.
Explanation for Sample Input/Output 2
Eat from box 2, from box 4, and from box 6.
Constraints
- For of the testdata, it is guaranteed that and .
- For of the testdata, it is guaranteed that and .
- For of the testdata, it is guaranteed that and .
Translated by ChatGPT 5
京公网安备 11011102002149号