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 aa;
long long a[200001] , one[200001] , two[200001] , ans ;
int main() {
cin >> aa;
for( int z = 0; z < aa; z++ ) cin >> a[z];
for( int z = 1; z < aa; z++ ) one[z] = one[z - 1] + max( (long long)0 , ( a[z - 1] - a[z] ) + 1 );
for( int z = aa - 2; z >= 0; z-- ) two[z] = two[z + 1] + max( (long long)0 , (a[z + 1] - a[z]) + 1 );
ans = 100000000000000000;
for( int z = 0; z < aa; z++ ) ans = min( ans , max( one[z] , two[z] ) );
cout << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |