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<iostream>
using namespace std;
int roz[1000000];
int t[1000000];
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>t[i];
if(i>1)
roz[i]=t[i]-t[i-1];
}
long long suma1=0;
long long suma2=0;
for(int i=1;i<n;i++)
if(roz[i]<=0)
suma1-=roz[i]-1;
long long wynik=suma1;
for(int i=n-1;i>=1;i--)
{
if(roz[i]<=0)
suma1+=roz[i]-1;
else suma2+=roz[i]+1;
if(roz[i]==0)
suma2++;
wynik=min(wynik,max(suma1,suma2));
}
cout<<wynik;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |