# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
862078 | vjudge1 | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++17 | 24 ms | 8736 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 ll long long
#define pii pair<int,int>
#define F first
#define S second
#define endl '\n'
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
const int mod = 1e9 + 7;
const int N = 1e6 + 15;
const ll inf = 1e18;
int a[N], n;
ll dp1[N], dp2[N];
int main(){
scanf("%d", &n);
for (int i=0;i<n;i++){
scanf("%d", a+i);
}
for (int i=1;i<n;i++){
dp1[i] = dp1[i-1] + max(0, a[i-1]-a[i]+1);
}
for (int i=n-2;i>=0;i--){
dp2[i] = dp2[i+1] + max(0, a[i+1]-a[i]+1);
}
ll ans = inf;
for (int i=0;i<n;i++){
ans = min(ans, max(dp1[i], dp2[i]));
}
printf("%lld", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |