Submission #936674

#TimeUsernameProblemLanguageResultExecution timeMemory
936674kitlixGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
24 ms1884 KiB
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { ios_base::sync_with_stdio(0), cin.tie(0); int n; cin >> n; vector<int> a(n); for (auto& el : a) cin >> el; int left = 0, right = 0; for (int i = 0; i + 1 < n; ++i) if (a[i] <= a[i + 1]) right += a[i + 1] - a[i] + 1; int best = right; for (int i = 1; i < n; ++i) { if (a[i - 1] <= a[i]) right -= a[i] - a[i - 1] + 1; if (a[i] <= a[i - 1]) left += a[i - 1] - a[i] + 1; best = min(best, max(left, right)); } cout << best; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...