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;
#ifdef ngu
#include "debug.h"
#else
#define debug(...) 42
#endif
#define int long long
const int N = (int) 2e5 + 5;
int n;
int a[N];
int L[N], R[N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
#ifdef ngu
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
#endif
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
if (i > 1) {
L[i] = L[i - 1] + max(0LL, a[i - 1] - a[i] + 1);
}
}
for (int i = n - 1; i >= 1; --i) {
R[i] = R[i + 1] + max(0LL, a[i + 1] - a[i] + 1);
}
const int INF = (int) 1e18;
int res = INF;
for (int i = 1; i <= n; ++i) {
res = min(res, max(L[i], R[i]));
}
cout << res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |