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 endl '\n'
using namespace std;
int a[200010];
long pref[200010],suf[200010],res=LONG_MAX;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++){
if(a[i]>a[i-1])pref[i]=pref[i-1];
else pref[i]=pref[i-1]+a[i-1]-a[i]+1;
}
for(int i=n-1;i>0;i--){
if(a[i]>a[i+1])suf[i]=suf[i+1];
else suf[i]=suf[i+1]+a[i+1]-a[i]+1;
}
for(int i=1;i<=n;i++)res=min(res,max(pref[i],suf[i]));
cout<<res<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |