# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1081286 | DeathIsAwe | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++17 | 71 ms | 7000 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;
#define int long long
int leftside[200001], rightside[200001];
int32_t main() {
int n; cin >> n;
vector<int> arr(n);
for (int i=0;i<n;i++) {
cin >> arr[i];
}
leftside[0] = 0;
for (int i=1;i<n;i++) {
leftside[i] = leftside[i-1] + max(arr[i-1] - arr[i] + 1, (int)0);
}
rightside[n-1] = 0;
for (int i=n-2;i>-1;i--) {
rightside[i] = rightside[i+1] + max(arr[i+1] - arr[i] + 1, (int)0);
}
int ans = INT_MAX, curans;
ans = min(leftside[n-1], rightside[0]);
for (int i=1;i<n-1;i++) {
ans = min(ans, max(leftside[i], rightside[i]));
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |