| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1355923 | truongthaiduonglaptrinh | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++20 | 0 ms | 344 KiB |
// duonglaptrinh
# include <bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
int n;
long long a[N], l[N], r[N];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if(fopen("nhap.inp", "r")) {
freopen("nhap.inp", "r", stdin);
freopen("nhap.out", "w", stdout);
}
cin>>n;
for(int i = 1; i <= n; i++) {
cin>>a[i];
}
for(int i = 1; i <= n; i++) {
l[i] = l[i - 1] + max(0LL, a[i - 1] - a[i] + 1);
}
for(int i = n; i >= 1; i--) {
r[i] = r[i + 1] + max(0LL, a[i + 1] - a[i] + 1);
}
long long ans = l[n];
for(int i = 1; i <= n; i++) {
long long s = max(l[i - 1], r[i]);
ans = min(ans, s);
}
cout<<ans;
return 0;
}
Compilation message (stderr)
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
