北语 12.6 五彩斑斓的梦想
点击查看代码
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e6+10;
int n;
LL a[N],s[N];
int main()
{
cin>>n;
LL sum=0;
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
s[i]=s[i-1]+a[i];
sum+=a[i];
}
LL del=0;
for(LL d=0;d<=n-1;d++){
LL t=d*(d+1);
if(t>s[d+1]) del=max(del,t-s[d+1]);
}
sum=sum+del;
cout<<sum;
return 0;
}

浙公网安备 33010602011771号