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;
using ll = long long;
const int N = 1e6 + 66;
ll A[N];
ll p[N], s[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n;
cin >> n;
for (int i = 1 ; i <= n ; ++ i) {
cin >> A[i];
}
ll ans = ll(1e18);
for (int i = 2 ; i <= n ; ++ i) {
p[i] = p[i - 1] + max(0ll, A[i - 1] + 1 - A[i]);
}
for (int i = n - 1 ; i >= 1 ; -- i) {
s[i] = s[i + 1] + max(0ll, A[i + 1] + 1 - A[i]);
}
for (int i = 1 ; i <= n ; ++ i) {
ans = min(ans, max(p[i], s[i]));
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |