Submission #1285883

#TimeUsernameProblemLanguageResultExecution timeMemory
1285883thinknoexitGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
15 ms1352 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int N = 200200; int a[N]; int main() { cin.tie(nullptr)->sync_with_stdio(false); int n; cin >> n; for (int i = 1;i <= n;i++) { cin >> a[i]; } ll ans = 0; int pl = 1, pr = n; while (pl < pr) { if (pl + 1 == pr) { if (a[pl] == a[pr]) { ans++; } break; } if (a[pl] < a[pl + 1]) pl++; else if (a[pr - 1] > a[pr]) pr--; else if (a[pl] - a[pl + 1] < a[pr] - a[pr - 1]) { ans += a[pl] - a[pl + 1] + 1; a[pr] -= a[pl] - a[pl + 1] + 1; pl++; } else { ans += a[pr] - a[pr - 1] + 1; a[pl] -= a[pr] - a[pr - 1] + 1; pr--; } } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...