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 f first
#define int long long
#define s second
using namespace std;
const int N=2e5+5,mod=1e9+7,Inf=1e15;
int t,n,ans,pref[N],suf[N],a[N];
string s;
main(){
// t=1;
cin >> n;
ans = Inf;
for(int i=1;i<=n;i++){
cin>>a[i];
if(i-1) pref[i] = pref[i-1] + max(0ll,a[i-1]-a[i]+1);
}
for(int i=n;i>=1;i--){
if(i!=n) suf[i] = suf[i+1] + max(0ll,a[i+1]-a[i]+1);
ans = min(ans,max(suf[i],pref[i]));
}
cout<<ans;
}
Compilation message (stderr)
Main.cpp:9:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
9 | main(){
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |