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 int long long
using namespace std;
signed main(){
int n;
cin>>n;
vector<int> v(n),pre(n),suf(n);
for(int &i:v) cin>>i;
for(int i=1;i<n;i++){
pre[i]=max(0LL,v[i-1]+1-v[i]);
pre[i]+=pre[i-1];
}
for(int i=n-2;i>=0;i--){
suf[i]=max(0LL,v[i+1]+1-v[i]);
suf[i]+=suf[i+1];
}
int ans=1e18;
for(int i=0;i<n;i++){
ans=min(ans,max(pre[i],suf[i]));
}
cout<<ans<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |