# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
530304 | Howard | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++14 | 1 ms | 332 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 main(){
int n;
long long ans, mn = (long long)1e9;
cin >> n;
long long a[n];
vector<long long> pos(n);
vector<long long> neg(n);
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 1; i < n; i++){
if(a[i] > a[i-1]) pos[i] = pos[i-1];
else if(a[i] < a[i-1]) pos[i] = pos[i-1] + a[i-1] - a[i] + 1;
else pos[i] = pos[i-1] + 1;
}
for(int i = n-2; i >= 0; i--){
if(a[i+1] < a[i]) neg[i] = neg[i+1];
else if(a[i+1] > a[i]) neg[i] = neg[i+1] + a[i+1] - a[i] + 1;
else neg[i] = neg[i+1] + 1;
}
for(int i = 0; i < n; i++){
if(pos[i] > neg[i]) mn = min(mn,pos[i]);
else mn = min(mn,neg[i]);
}
cout << mn << endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |