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>
#define ll long long
using namespace std;
ll arr[200000];
ll izq[200000];
ll der[200000];
int main()
{
std::ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n;
cin>>n;
for(ll i=0;i<n;i++)
{
cin>>arr[i];
}
izq[0]=0;
for(ll i=1;i<n;i++)
{
izq[i]=izq[i-1]+max((long long)0,arr[i-1]-arr[i]+1);
}
der[n-1]=0;
for(ll i=n-2;i>=0;i--)
{
der[i]=der[i+1]+max((long long)0,arr[i+1]-arr[i]+1);
}
ll cont=max(der[0],izq[0]);
for(ll i=1;i<n;i++)
{
cont=min(cont,max(der[i],izq[i]));
}
cout<<cont;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |