// File vegetables4.cpp created on 30.09.2025 at 19:13:23
#include <bits/stdc++.h>
using i64 = long long;
#ifdef DEBUG
#include "/home/ahmetalp/Desktop/Workplace/debug.h"
#else
#define debug(...) void(23)
#endif
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int N;
std::cin >> N;
std::vector<int> A(N);
for (int i = 0; i < N; ++i) {
std::cin >> A[i];
}
std::vector<i64> pre(N), suf(N);
for (int i = 0; i + 1 < N; ++i) {
pre[i + 1] = pre[i] + std::max(0, 1 + A[i] - A[i + 1]);
}
for (int i = N - 1; i > 0; --i) {
suf[i - 1] = suf[i] + std::max(0, 1 + A[i] - A[i - 1]);
}
i64 ans = i64(1E18);
for (int i = 0; i < N; ++i) {
ans = std::min(ans, std::max(pre[i], suf[i]));
}
std::cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |