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