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>
typedef long long ll;
using namespace std;
ll a[200002], pref[200002], suff[200002];
int main() {
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) pref[i] = pref[i - 1] + max(0ll, a[i - 1] - a[i] + 1);
for (int i = n; i; i--) suff[i] = suff[i + 1] + max(0ll, a[i + 1] - a[i] + 1);
ll ans = LLONG_MAX;
for (int i = 1; i < n; i++)
ans = min(ans, max(pref[i], suff[i + 1]) + (a[i] + pref[i] == a[i + 1] + suff[i + 1]));
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |