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;
#define nmax 200003
int v[nmax];
int main()
{
int n, i, x, y, rez = 0;
cin >> n;
for( i = 0; i < n; i++ )
cin >> v[i];
x = 0;
y = n - 1;
while( y - x > 0 ) {
if( v[x] < v[x+1] )
x++;
else if( v[y-1] > v[y] )
y--;
else {
if( v[x] - v[x+1] + 1 < v[y] - v[y-1] + 1 ) {
rez += v[x] - v[x+1] + 1;
v[y] -= v[x] - v[x+1] + 1;
x++;
} else {
rez += v[y] - v[y-1] + 1;
v[x] -= v[y] - v[y-1] + 1;
y--;
}
}
/*cout << rez << " ";
for( i = 0; i < n; i++ )
cout << v[i] << " ";
cout << "\n";*/
}
cout << rez;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |