# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
736391 | shoryu386 | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++17 | 1074 ms | 1740 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;
#define int long long
int n;
int arr[200007];
int solve(int tp){
int linc = 0;
for (int x = 1; x <= tp; x++){
if (arr[x-1] >= arr[x]){
//enforce an increase
linc += arr[x-1] - arr[x] + 1;
}
}
int rinc = 0;
for (int x = n-2; x >= tp; x--){
if (arr[x+1] >= arr[x]){
//enforce an increase
rinc += arr[x+1] - arr[x] + 1;
}
}
//cout << tp << ' ' << linc << ' ' << rinc << '\n';
return max(linc, rinc);
}
main(){
cin >> n; for (int x = 0; x < n; x++) cin >> arr[x];
int ans = LLONG_MAX/100;
for (int x = 0; x < n; x++) ans = min(ans, solve(x));
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |