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;
#define int long long
int32_t main()
{
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
vector<int> a(n + 1);
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<int> one(n + 1), two(n + 2);
for(int i = 2; i <= n; i++) {
one[i] = one[i - 1] + max(a[i - 1] - a[i] + 1, 0LL);
}
for(int i = n - 1; i >= 1; i--) {
two[i] = two[i + 1] + max(a[i + 1] - a[i] + 1, 0LL);
}
const int oo = 1e18;
int ans = oo;
for(int i = 1; i <= n; i++) {
ans = min(ans, max(one[i], two[i]));
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |