# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
397663 | ChrisT | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++17 | 38 ms | 6212 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;
const int MN = 1e6 + 5;
int main () {
int n;
scanf ("%d",&n);
vector<long long> pre(n+1), suf(n+2);
vector<int> a(n+1);
long long ret = 1e18;
for (int i = 1; i <= n; i++) {
scanf ("%d",&a[i]);
if (i > 1) pre[i] = pre[i-1] + max(0,a[i-1] - a[i] + 1);
}
for (int i = n; i >= 1; i--) {
if (i < n) suf[i] = suf[i+1] + max(0,a[i+1] - a[i] + 1);
ret = min(ret,max(pre[i],suf[i]));
}
printf ("%lld\n",ret);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |