Submission #657230

#TimeUsernameProblemLanguageResultExecution timeMemory
657230deviceGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 ms212 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] - a[i-1] + 1, 0ll); } for (int i = n-1; i >= 1; i--) { ss[i] = ss[i+1] + max(a[i] - a[i+1] + 1, 0ll); } for (int i = 1; i <= n; i++) { ans = min(ans, ps[i] + ss[i+1]); } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...