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>
#include <vector>
#include <algorithm>
using namespace std;
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
int n; cin >> n;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) cin >> a[i];
vector<int> left(n + 1), right(n + 1);
for (int i = 2; i <= n; i++) {
left[i] = left[i - 1] + max(0, a[i - 1] - a[i] + 1);
}
for (int i = n - 1; i > 0; i--) {
right[i] = right[i + 1] + max(0, a[i + 1] - a[i] + 1);
}
int ans = min(right[1], left[n]);
for (int i = 2; i <= n; i++) {
ans = min(ans, max(left[i], right[i]));
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |