# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
586144 | hibiki | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++11 | 31 ms | 6928 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;
int n;
long long a[200005];
long long dpl[200005], dpr[200005];
int main()
{
scanf("%d",&n);
for(int i = 0; i < n; i++)
scanf("%lld",&a[i]);
for(int i = 1; i < n; i++)
dpl[i] = dpl[i - 1] + max(a[i - 1] - a[i] + 1, 0ll);
for(int i = n - 2; i >= 0; i--)
dpr[i] = dpr[i + 1] + max(a[i + 1] - a[i] + 1, 0ll);
long long ans = min(dpl[n - 1], dpr[0]);
for(int i = 0; i < n; i++)
{
// printf("%lld %lld\n", dpl[i], dpr[i]);
ans = min(ans, max(dpl[i], dpr[i + 1]) + max(a[i + 1] - a[i] + dpr[i + 1] - dpl[i] + 1, 0ll));
}
printf("%lld\n",ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |