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;
int n,a[200005],pref[200005],suf[200005],ans=1999999999;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
pref[i]=max((a[i-1]+pref[i-1])-a[i]+1,0);
// cout<<pref[i]<<' ';
}
// cout<<endl;
for(int i=n;i>=1;i--){
suf[i]=max((a[i+1]+suf[i+1])-a[i]+1,0);
// cout<<suf[i]<<' ';
}
// cout<<endl;
for(int i=0;i<=n;i++){
// cout<<i<<' '<<pref[i]<<' '<<suf[i+1]<<endl;
if(a[i]+pref[i]==a[i+1]+suf[i+1]) ans=min(ans,max(pref[i],suf[i+1])+1);
else ans=min(ans,max(pref[i],suf[i+1]));
}
cout<<ans<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |