思路:
for循环贪心;
代码:
#include <bits/stdc++.h>
using namespace std;
#define maxn 100005
#define ll long long
ll ai[maxn],n,m,ans;
inline void in(ll &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'')Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
}
int main()
{
in(n),in(m);
for(ll i=;i<=n;i++)
{
in(ai[i]);
if(ai[i]+ai[i-]>m)
{
ans+=ai[i]+ai[i-]-m;
ai[i]-=ai[i]+ai[i-]-m;
}
}
cout<<ans;
return ;
}