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;
typedef long long ll;
ll a[200001];
int main() {
int n;
ll c = 0, x;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int j = 0, k = n - 1;
while (1) {
while (j < k && a[j] < a[j + 1]) {
j++;
}
while (k > j && a[k] < a[k - 1]) {
k--;
}
if (j + 1 == k) {
c++;
j++;
}
if (j == k) {
break;
}
x = min(a[j] - a[j + 1], a[k] - a[k + 1]) + 1;
c += x;
a[j] -= x;
a[k] -= x;
}
cout << c << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |