求助!#2和#10 TLE了
查看原帖
求助!#2和#10 TLE了
831458
ChenHyz楼主2023/1/27 14:16
#include <bits/stdc++.h>
using namespace std;
const int maxsize = 1e5+5;
int main(){
	long long n,x,a[maxsize],cnt=0;
	cin>>n>>x;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	
	for(int i=1,j=2;i<n,j<=n;i++,j++)
	{
		if(a[i]+a[j]>x)
		{
			while(a[i]+a[j]>x&&a[j]!=0)
				{
					cnt++;
					a[j]--;
				}//while
				while(a[i]+a[j]>x&&a[i]!=0)
				{
					cnt++;
					a[i]--;
				}//while
		}//if
	}//for
	cout<<cnt<<endl;
	return 0;
}
2023/1/27 14:16
加载中...