# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
698823 | US3RN4M3 | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++17 | 87 ms | 6200 KiB |
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;
using ll = long long;
const int mx = 200005;
int A[mx];
ll pref_cost[mx];
ll suff_cost[mx];
int n;
main() {
cin >> n;
for(int i = 1; i <= n; i++) cin >> A[i];
for(int i = 1; i <= n + 1; i++) pref_cost[i] = pref_cost[i - 1] + max(0, 1 + A[i - 1] - A[i]);
for(int i = n; i >= 0; i--) suff_cost[i] = suff_cost[i + 1] + max(0, 1 + A[i + 1] - A[i]);
ll ans = 1e18;
for(int i = 0; i <= n; i++) {
ans = min(ans, max(pref_cost[i], suff_cost[i]));
}
cout << ans << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |