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 ll = long long;
const int MAX_N = 200000;
ll a[MAX_N + 1], l[MAX_N + 1], r[MAX_N + 1];
int main() {
int n;
std::cin >> n;
for (int i = 1; i <= n; i++) {
std::cin >> a[i];
}
for (int i = 1; i <= n; i++) {
l[i] = l[i - 1] + std::max(0LL, a[i - 1] - a[i] + 1);
}
for (int i = n; i >= 1; i--) {
r[i] = r[i + 1] + std::max(0LL, a[i + 1] - a[i] + 1);
}
ll answer = (1LL << 60);
for (int i = 1; i <= n; i++) {
answer = std::min(answer, std::max(l[i], r[i]));
}
std::cout << answer;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |