Submission #1243355

#TimeUsernameProblemLanguageResultExecution timeMemory
1243355Bui_Quoc_CuongGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
13 ms4272 KiB
#include <bits/stdc++.h> using namespace std; int n; int a[5'000'05]; long long pre[5'000'05], suf[5'000'05]; signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n; i++){ pre[i] = pre[i - 1] + max(0, a[i - 1] - a[i] + 1); } for(int i = n; i >= 1; i--){ suf[i] = suf[i + 1] + max(0, a[i + 1] - a[i] + 1); } long long ans = 1e18; for(int i = 1; i <= n; i++){ ans = min(ans, max(pre[i], suf[i])); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...