# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
756776 | otarius | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++17 | 2 ms | 212 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 ll long long
void solve() {
int n;
cin >> n;
int arr[n + 1], ans = 1e18;
for (int i = 1; i <= n; i++)
cin >> arr[i];
int pref[n + 1], suff[n + 1];
pref[1] = 0; suff[n] = 0;
for (int i = 2; i <= n; i++) {
if (arr[i - 1] < arr[i])
pref[i] = pref[i - 1];
else pref[i] = pref[i - 1] + arr[i - 1] - arr[i] + 1;
}
for (int i = n - 1; i >= 1; i--) {
if (arr[i] > arr[i + 1])
suff[i] = suff[i + 1];
else suff[i] = suff[i + 1] + arr[i + 1] - arr[i] + 1;
} for (int i = 1; i <= n; i++) {
ans = min(ans, max(pref[i], suff[i]));
} cout << ans;
}
int main() {
int t = 1;
// cin >> t;
while (t--) {
solve();
cout << '\n';
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |