Submission #783264

#TimeUsernameProblemLanguageResultExecution timeMemory
783264borisAngelovGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
22 ms6168 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; int n; int a[maxn]; long long preffix[maxn]; long long suffix[maxn]; void fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { fastIO(); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } for (int i = 2; i <= n; ++i) { preffix[i] = preffix[i - 1] + max(0, a[i - 1] - a[i] + 1); } for (int i = n - 1; i >= 1; --i) { suffix[i] = suffix[i + 1] + max(0, a[i + 1] - a[i] + 1); } long long ans = (1ll << 62); for (int i = 1; i <= n; ++i) { ans = min(ans, max(preffix[i], suffix[i])); } cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...