AC日记——小A的糖果 洛谷七月月赛
思路:
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=0; while(Cget>'9'||Cget<'0')Cget=getchar(); while(Cget>='0'&&Cget<='9') { now=now*10+Cget-'0'; Cget=getchar(); } } int main() { in(n),in(m); for(ll i=1;i<=n;i++) { in(ai[i]); if(ai[i]+ai[i-1]>m) { ans+=ai[i]+ai[i-1]-m; ai[i]-=ai[i]+ai[i-1]-m; } } cout<<ans; return 0; }