# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
942159 | dsyz | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++17 | 1006 ms | 5464 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;
using ll = long long;
#define MAXN (1000005)
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);
ll N;
cin>>N;
ll arr[N], A[N];
for(ll i = 0;i < N;i++){
cin>>arr[i];
A[i] = arr[i];
}
ll ans = 1e18;
for(ll split = 0;split < N;split++){
ll total = 0;
ll Ldiff = 0,Rdiff = 0;
for(ll i = 1;i <= split;i++){
total += max(0ll,(arr[i - 1] + 1) - arr[i]);
Ldiff += max(0ll,(arr[i - 1] + 1) - arr[i]);
}
for(ll i = N - 2;i >= split;i--){
total += max(0ll,(arr[i + 1] + 1) - arr[i]);
Rdiff += max(0ll,(arr[i + 1] + 1) - arr[i]);
}
total -= min(Ldiff,Rdiff);
ans = min(ans,total);
}
cout<<ans<<'\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |