Submission #657236

#TimeUsernameProblemLanguageResultExecution timeMemory
657236deviceGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
81 ms6940 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n, ans = 1e18, a[200005], ps[200005], ss[200005]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 2; i <= n; i++) { ps[i] = ps[i-1] + max(a[i-1] - a[i] + 1, 0ll); } for (int i = n-1; i >= 1; i--) { ss[i] = ss[i+1] + max(a[i+1] - a[i] + 1, 0ll); } for (int i = 1; i <= n; i++) { ans = min(ans, max(ps[i], ss[i])); } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...