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 ll long long
#define endl '\n'
#define ios ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
using namespace std;
int main() {
ios
int n;
cin >> n;
ll a[n + 2];
for (int i = 0; i < n; ++ i) {
cin >> a[i];
}
ll f = 0, s = 0;
for (int i = 0; i < n - 1; ++ i) {
s += max(0ll, a[i + 1] - a[i] + 1);
}
ll ans = s;
for (int i = 1; i < n; ++ i) {
s -= max(0ll, a[i] - a[i - 1] + 1);
f += max(0ll, a[i - 1] - a[i] + 1);
ans = min(ans, max(f, s));
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |