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
const int inf=1e18;
signed main()
{
int n;cin>>n;
int a[n+50]={0};for(int i=1;i<=n;i++)cin>>a[i];
int pref[n+50]={0},suf[n+50]={0};
for(int i=1;i<=n;i++)
{
int x=a[i-1]-a[i]+1;if(x<0) x=0;
pref[i]=pref[i-1]+x;
int j=n-i+1;
x=a[j+1]-a[j]+1;if(x<0) x=0;
suf[j]=suf[j+1]+x;
}
/*for(int i=1;i<=n;i++)printf("%i ",pref[i]);
printf("\n");
for(int i=1;i<=n;i++)printf("%i ",suf[i]);
printf("\n");*/
int res=inf;
for(int i=1;i<=n;i++)
{
int x=max(pref[i],suf[i]);
res=min(res,x);
}
cout<<res<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |