Submission #747267

#TimeUsernameProblemLanguageResultExecution timeMemory
747267JellyTheOctopusGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
40 ms10180 KiB
#include <bits/stdc++.h> using namespace std; int N; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N; vector<long long> arr(N+1); for (int i = 1; i <= N; i++) { cin >> arr[i]; } vector<long long> prefixAdd(N+1), prefixVal(N+1); for (int i = 1; i <= N; i++) { prefixVal[i] = arr[i]+prefixAdd[i-1]; prefixAdd[i] = prefixAdd[i-1]; if (prefixVal[i] <= prefixVal[i-1]+1) { prefixAdd[i] += (prefixVal[i-1]-prefixVal[i]+1); prefixVal[i] = prefixVal[i-1]+1; } } vector<long long> suffixAdd(N+2), suffixVal(N+2); for (int i = N; i >= 1; i--) { suffixVal[i] = arr[i]+suffixAdd[i+1]; suffixAdd[i] = suffixAdd[i+1]; if (suffixVal[i] <= suffixVal[i+1]+1) { suffixAdd[i] += (suffixVal[i+1]-suffixVal[i]+1); suffixVal[i] = suffixVal[i+1]+1; } } long long ans = LLONG_MAX; for (int i = 1; i <= N; i++) { ans = min(ans, max(prefixAdd[i], suffixAdd[i])); } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...