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 fi first
#define se second
#define pb push_back
#define debug(x) cout<<#x<<": "<<x<<"\n"
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// freopen("input.000","r",stdin);
// freopen("output.000","w",stdout);
// srand((unsigned)time(NULL));
// rand()
int n,i,a[200005],l[200005],r[200005],ans;
cin>>n;
for (i=1;i<n+1;i++) cin>>a[i];
l[1]=0;
for (i=2;i<n+1;i++) l[i]=max(0ll, a[i-1]-a[i]+1);
for (i=3;i<n+1;i++) l[i] += l[i-1];
r[n]=0;
for (i=n-1;i>0;i--) r[i]=max(0ll, a[i+1]-a[i]+1);
for (i=n-2;i>0;i--) r[i] += r[i+1];
ans=1e18;
for (i=1;i<n+1;i++) ans=min(ans,max(l[i],r[i]));
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |