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;
const long long MX=2e5+10;
const long long INF=1e18;
long long a[MX],pr[MX],syf[MX];
int main()
{
cin.tie(0);
ios_base::sync_with_stdio(0);
long long n;
cin>>n;
for(long long i=1;i<=n;i++)
{
cin>>a[i];
}
for(long long i=2;i<=n;i++)
{
pr[i]=pr[i-1]+max(0LL,a[i-1]+1-a[i]);
}
for(long long i=n-1;i>=1;i--)
{
syf[i]=syf[i+1]+max(0LL,a[i+1]+1-a[i]);
}
long long ans=INF;
for(long long i=1;i<=n;i++)
{
ans=min(ans,max(pr[i],syf[i]));
}
cout<<ans<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |