# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
508902 | ITO | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++11 | 96 ms | 7016 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;
typedef long long ll;
ll a[200001], b[200001][2];
int main() {
int n;
ll c = 100000000000000000, x, cl = 0, cr = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
b[0][0] = 0;
b[n - 1][1] = 0;
for (int i = 1; i < n; i++) {
b[i][0] = b[i - 1][0] + max(0ll, a[i - 1] - a[i] + 1);
}
for (int i = n - 2; i >= 0; i--) {
b[i][1] = b[i + 1][1] + max(0ll, a[i + 1] - a[i] + 1);
}
for (int i = 0; i < n; i++) {
c = min(c, max(b[i][0], b[i][1]));
}
cout << c << '\n';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |