This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n;
cin>>n;
ll cad[n];
ll ac[n];
ll ma=0;
for(int i=0; i<n; i++)
{
cin>>cad[i];
ac[i]=max(ma-cad[i],0LL);
ma=cad[i]+1;
if(i>0)
ac[i]+=ac[i-1];
}
ll bs=1e9+7;
ll sol=0;
ma=0;
for(int i=n-1; i>=0; i--)
{
sol+=max(ma-cad[i],0LL);
ma=cad[i]+1;
bs=min(bs,max(sol,ac[i]));
}
cout<<bs;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |