#P3817. 小A的糖果

小A的糖果

Description

Xiao A has nn candy boxes; the ii-th box contains aia_i 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 xx, what is the minimum number of candies he must eat.

Input Format

The first line contains two space-separated integers, the number of boxes nn and the given parameter xx.

The second line contains nn space-separated integers; the ii-th integer is aia_i, the number of candies in the ii-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 66 from box 2, 22 from box 4, and 33 from box 6.


Constraints

  • For 30%30\% of the testdata, it is guaranteed that n20n \leq 20 and ai,x100a_i, x \leq 100.
  • For 70%70\% of the testdata, it is guaranteed that n103n \leq 10^3 and ai,x105a_i, x \leq 10^5.
  • For 100%100\% of the testdata, it is guaranteed that 2n1052 \leq n \leq 10^5 and 0ai,x1090 \leq a_i, x \leq 10^9.

Translated by ChatGPT 5