# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
568681 | dantoh000 | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++14 | 41 ms | 11656 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>
#define int long long
using namespace std;
int n;
int a[200005];
int diff[200005];
int c[200005];
int d[200005];
int pc[200005];
int pd[200005];
main(){
scanf("%lld",&n);
for (int i = 0; i < n; i++){
scanf("%lld",&a[i]);
if (i) diff[i] = a[i]-a[i-1];
}
for (int i = 1; i < n; i++){
c[i] = max(0ll,1-diff[i]);
d[i] = max(0ll,diff[i]+1);
///printf("%d: to 1 = %d, to -1 = %d\n",diff[i],c[i],d[i]);
pc[i] = pc[i-1] + c[i];
}
for (int i = n-1; i >= 1; i--){
pd[i] = pd[i+1] + d[i];
}
int ans = -1;
for (int i = 1; i <= n; i++){
int NC = max(pc[i-1],pd[i]);
if (ans == -1 || ans > NC) ans = NC;
}
printf("%lld\n",ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |