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;
ll ori[200010],pre[200010]={},pb[200010]={};
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
ll n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>ori[i];
}
for(int i=2;i<=n;i++){
pre[i]=pre[i-1];
if(ori[i]<=ori[i-1]){
pre[i]+=ori[i-1]-ori[i]+1;
}
}
for(int i=n;i>=1;i--){
pb[i]=pb[i+1];
if(ori[i]<=ori[i+1]){
pb[i]+=ori[i+1]-ori[i]+1;
}
}
ll ans=100000000000000000;
for(int i=1;i<=n;i++){
ans=min(ans,max(pre[i],pb[i]));
}
cout<<ans<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |