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>
const int maxn = 1e6 + 5;
int n;
int a[maxn + 5];
long long pref[maxn + 5], suff[maxn + 5];
void solve() {
std::cin >> n;
for (int i = 1; i <= n; ++i) std::cin >> a[i];
for (int i = 1; i <= n; ++i) {
pref[i] = pref[i - 1];
if (a[i] <= a[i - 1])
pref[i] += a[i - 1] - a[i] + 1;
}
for (int i = n; i >= 1; --i) {
suff[i] = suff[i + 1];
if (a[i] <= a[i + 1])
suff[i] += a[i + 1] - a[i] + 1;
}
long long ans = 1e15;
for (int i = 1; i <= n; ++i) {
ans = std::min(ans, std::max(pref[i], suff[i]));
}
std::cout << ans;
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
int tc = 1;
// std::cin >> tc;
// init();
while (tc--) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |