Submission #621503

#TimeUsernameProblemLanguageResultExecution timeMemory
621503elkernosGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
27 ms6988 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { cin.tie(0)->sync_with_stdio(0); int n; cin >> n; vector<int> a(n + 1); for(int i = 1; i <= n; i++) { cin >> a[i]; } vector<int> one(n + 1), two(n + 2); for(int i = 2; i <= n; i++) { one[i] = one[i - 1] + max(a[i - 1] - a[i] + 1, 0LL); } for(int i = n - 1; i >= 1; i--) { two[i] = two[i + 1] + max(a[i + 1] - a[i] + 1, 0LL); } const int oo = 1e18; int ans = oo; for(int i = 1; i <= n; i++) { ans = min(ans, max(one[i], two[i])); } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...