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;
int main()
{
long long n;
cin>>n;
long long niza[n];
for(long long i=0; i<n; i++)
{
cin>>niza[i];
}
long long a[n],b[n];
a[0]=0,b[n-1]=0;
for(long long i=1; i<n; i++)
{
a[i]=a[i-1];
if(niza[i]<=niza[i-1])
{
a[i]+=niza[i-1]-niza[i]+1;
}
}
for(long long i=n-2; i>=0; i--)
{
b[i]=b[i+1];
if(niza[i]<=niza[i+1])
{
b[i]+=niza[i+1]-niza[i]+1;
}
}
long long res=1e18;
for(long long i=0; i<n; i++)res=min(res,max(a[i],b[i]));
cout<<res<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |