https://www.luogu.com.cn/problem/P3817
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
template<typename DataType>
DataType qmi(DataType m, int k)
{
DataType res = 1, t = m;
while (k)
{
if (k&1) res = res * t;
t = t * t;
k >>= 1;
}
return res;
}
int read(){
int x = 0,f = 1;
char c = getchar();
while (c<'0'||c>'9') {
if (c=='-') {
f = -1;
}
c = getchar();
}
while (c>='0'&&c<='9') {
x = x*10+c-'0';
c = getchar();
}
return x*f;
}
#define fi(a,b) for(int i = a; i <= b; i++)
#define fj(a,b) for(int j = a; j >= b; j--)
struct MAP{
int pos;
int data;
};
void quickSort(MAP *a,int left,int right){
int i,j;
MAP temp,t;
temp = a[(left+right)/2];//基准值
i = left;
j = right;
while(i<=j){
while (a[j].data > temp.data) {
j--;
}
while (a[i].data < temp.data) {
i++;
}
if (i<=j) {
t = a[i];
a[i] = a[j];
a[j] = t;
//继续下一步
i++;
j--;
}
}
if(left<j)quickSort(a,left, j);//继续分治
if(i<right)quickSort(a,i, right);//继续分治
}
//const int maxNum = 255;
//MAP num[maxNum];
//MAP num1[maxNum];
int n,x;
int main()
{
long long sum=0;//计数器,n,x;
cin>>n>>x;//输入
long long a[n+1];
cin>>a[1];//处理第一个单独超限。
if(a[1]>x)
{
sum+=a[1]-x;//增加吃的量
a[1]=x;//a[i]>=x,要吃的最少,即是a[i]=x;
}
for(int i=2;i<=n;i++)
{
cin>>a[i];//输入
if(a[i]+a[i-1]>x)//照例处理
{
sum+=a[i]+a[i-1]-x;
a[i]=x-a[i-1];
}
}
cout<<sum;//输出
return 0;//养成好习惯
}
/*
3 3
2 2 2
============
1
*/
网友评论