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;
long long n , a [200005] , suma , sumb , ans = 1e18 , dif [200005] , rdif [200005];
int main ()
{
cin >> n;
for ( int i = 1 ; i <= n ; i ++ )
{
cin >> a [i];
if ( i != 1 ) dif [i] = max ( 0ll , a [ i - 1 ] - a [i] + 1 );
dif [i] += dif [ i - 1 ];
}
for ( int i = n ; i >= 1 ; i -- )
{
if ( i != n ) rdif [i] = max ( 0ll , a [ i + 1 ] - a [i] + 1 );
rdif [i] += rdif [ i + 1 ];
}
for ( int i = 1 ; i <= n ; i ++ ) ans = min ( ans , max ( dif [i] , rdif [i] ) );
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |