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 MAXN 200010
long long n;
long long niz[MAXN];
long long p[MAXN];
long long pref[MAXN],suf[MAXN];
int main()
{
cin>>n;
for (long long i=1;i<=n;i++) cin>>niz[i];
p[1]=niz[1];
for (long long i=2;i<=n;i++) p[i]=niz[i]-niz[i-1];
for (long long i=1;i<=n;i++)
{
if (p[i]>0) pref[i]=pref[i-1];
else pref[i]=pref[i-1]+(p[i]*(-1)+1);
}
for (long long i=n;i>=1;i--)
{
if (p[i]<0) suf[i]=suf[i+1];
else suf[i]=suf[i+1]+p[i]+1;
}
long long maksi=2000000010;
for (long long i=0;i<=n;i++)
{
maksi=min(maksi,max(pref[i],suf[i+1]));
}
cout<<maksi<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |