Samkit and Folders

0

0 votes
Easy
Problem

There are folders arranged in a row on a desktop.Initially th folder as Ai files.

Samkit can perform the following operation any number of times : 

  • Choose a folder containing atleast one file and delete one of the files from choosen folder

His Goal is as follows 

  • Any two neighboring folders contain at most x files in total.

Find minimum number of operations that Samkit need to perform.

INPUT

First Line Contains two integers N and x.

Second Line Contains N integers giving number of files in N folders each.

OUTPUT

Print the minimum number of operations required to achieve the goal.

CONSTRAINTS

2<=N<=105

0<=Ai<=109

0<=x<=109

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Delete one File in the second Folder. Then, the number of Files in each Folder becomes (2,1,2).

Editor Image

?