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 ll long long
using namespace std;
int main(){
ll n;
cin>>n;
ll a[n+1],b[n+1];
for (int i=1;i<=n;i++){
cin>>a[i];b[i]=a[i];
}
ll pref[n+1],suff[n+1];
pref[1]=0;
for (int i=2;i<=n;i++){
pref[i]=max(pref[i-1],a[i-1]+1-a[i]);
a[i]=max(a[i-1]+1,a[i]);
}
suff[n]=0;
for (int i=n-1;i>=1;i--){
suff[i]=max(suff[i+1],b[i+1]+1-b[i]);
b[i]=max(b[i+1]+1,b[i]);
}
ll ans=-1;
for (int i=1;i<=n;i++){
if (ans==-1)ans=max(suff[i],pref[i]);
ans=min(ans,max(suff[i],pref[i]));
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |