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;
#define int long long
#define all(x) x.begin(),x.end()
int INF=1e18;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
vector<int> v(n+2);
for(int i=1;i<=n;i++){
cin>>v[i];
}
vector<int> pre(n+2),suf(n+2);
for(int i=1;i<=n;i++){
int t=max((int)0,v[i-1]+1-v[i]);
pre[i]=pre[i-1]+t;
}
for(int i=n;i>=1;i--){
int t=max((int)0,v[i+1]+1-v[i]);
suf[i]=suf[i+1]+t;
}
int ans=INF;
for(int i=1;i<=n;i++){
ans=min(ans,max(pre[i],suf[i]));
}
cout<<ans<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |