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>
#define N 200005
using namespace std;
long long n,i,a[N],v[N],w[N],p[N],s[N],mn=2e18;
int main()
{
cin>>n;
for(i=1;i<=n;++i)
{
cin>>a[i];
}
for(i=1;i<=n;++i)
{
if(i==1){v[i]=0; continue;}
if(a[i]>(a[i-1]+v[i-1]))
{
v[i]=0;
}
else
{
v[i]=(a[i-1]+v[i-1])-a[i]+1;
}
}
for(i=n;i>=1;--i)
{
if(i==n){w[i]=0; continue;}
if(a[i]>(a[i+1]+w[i+1]))
{
w[i]=0;
}
else
{
w[i]=(a[i+1]+w[i+1])-a[i]+1;
}
}
for(i=1;i<=n;++i)
{
if(i==1){p[i]=0; continue;}
if(v[i]>v[i-1]) p[i]=p[i-1]+(v[i]-v[i-1]);
else p[i]=p[i-1];
}
for(i=n;i>=1;--i)
{
if(i==n){s[i]=0; continue;}
if(w[i]>w[i+1]) s[i]=s[i+1]+(w[i]-w[i+1]);
else s[i]=s[i+1];
}
for(i=1;i<=n;++i)
{
mn=min(mn,max(p[i],s[i]));
}
cout<<mn;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |