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 <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <iomanip>
#include <cassert>
#include <deque>
#include <functional>
#include <set>
#include <queue>
#include <map>
using namespace std;
#define int long long
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (int& i : a) cin >> i;
int ans = 1e18;
vector<int> pref(n, 0);
vector<int> suff(n, 0);
for (int i = 1; i < n; ++i) {
pref[i] = pref[i - 1] + max(0ll, a[i - 1] - a[i] + 1);
}
for (int i = n - 2; i >= 0; --i) {
suff[i] = suff[i + 1] + max(0ll, a[i + 1] - a[i] + 1);
}
for (int i = 0; i < n; ++i) {
ans = min(ans, max(pref[i], suff[i]));
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |