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>
#define pb push_back
using namespace std;
typedef long long ll;
const int N = 3e5;
const ll INF = 1e18;
int n, a[N];
ll p[N], s[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
int d = a[i] - a[i - 1];
p[i] = p[i - 1] + max(0, 1 - d);
}
for (int i = n - 1; i >= 1; i--) {
int d = a[i + 1] - a[i];
s[i] = s[i + 1] + max(0, 1 + d);
}
ll ans = INF;
for (int i = 1; i <= n; i++) {
ans = min(ans, max(p[i], s[i]));
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |