This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
using ll = long long;
template<class T> using V = vector<T>;
const ll INF = 1e18;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N; cin >> N;
V<ll> A(N); for(auto& x : A) cin >> x;
V<ll> P(N), S(N);
P[0] = 0;
for(int i = 1; i < N; i++) {
P[i] = P[i-1] + max(A[i-1] - A[i] + 1, 0LL);
}
S[N-1] = 0;
for(int i = N-2; i >= 0; i--) {
S[i] = S[i+1] + max(A[i+1] - A[i] + 1, 0LL);
}
// for(int i = 0; i < N; i++) {
// cout << P[i] << " | " << S[i] << endl;
// }
ll ans = INF;
for(int mid = 0; mid < N; mid++) {
ans = min(ans, max(P[mid], S[mid]));
}
cout << ans << nl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |