# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1183312 | alterio | Growing Vegetables is Fun 4 (JOI21_ho_t1) | C++20 | 0 ms | 400 KiB |
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define all(x) (x).begin(), (x).end()
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
vector<int> ansL(n), ansR(n);
for (int i = 1; i < n; i++) ansL[i] = ansL[i - 1] + max(0, v[i - 1] - v[i] + 1);
for (int i = n - 2; i >= 0; i--) ansR[i] = ansR[i + 1] + max(0, v[i + 1] - v[i] + 1);
int ans = 1e10;
for (int i = 0; i < n; i++) ans = min(ans, max(ansL[i], ansR[i]));
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |