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;
typedef long long ll;
ll df[200006];
ll N, i, v = 0, L, R, ans = 0, d, tp;
int main()
{
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> tp;
df[i] = tp - v;
v = tp;
}
L = 2;
R = N;
while (L <= R) {
if (df[L] > 0)
L++;
else if (df[R] < 0)
R--;
else if (L == R) {
if (df[L] == 0)
ans++;
L++;
} else {
d = min(-df[L] + 1, df[R] + 1);
ans += d;
df[L] += d;
df[R] -= d;
}
}
cout << ans << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |