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;
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int &v : A) {
cin >> v;
}
vector<long long> pref(N), suff(N);
for (int i = 0; i < N - 1; i++) {
pref[i + 1] = pref[i] + max(0, A[i] - A[i + 1] + 1);
}
for (int i = N - 2; i >= 0; i--) {
suff[i] = suff[i + 1] + max(0, A[i + 1] - A[i] + 1);
}
long long ans = LLONG_MAX;
for (int i = 0; i < N; i++) {
ans = min(ans, max(pref[i], suff[i]));
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |