# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
620797 | patrikpavic2 | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++17 | 45 ms | 6232 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 <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 2e5 + 500;
int n, A[N];
ll dpL[N], dpR[N];
int main(){
scanf("%d", &n);
for(int i = 0;i < n;i++)
scanf("%d", A + i);
for(int i = 1;i < n;i++)
dpL[i] = dpL[i - 1] + max(0, 1 - (A[i] - A[i - 1]));
for(int i = n - 2;i >= 0;i--)
dpR[i] = dpR[i + 1] + max(0, 1 - (A[i] - A[i + 1]));
ll ans = (ll)1e18;
for(int i = 0;i < n;i++)
ans = min(ans, max(dpL[i], dpR[i]));
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... |