Submission #747264

#TimeUsernameProblemLanguageResultExecution timeMemory
747264JellyTheOctopusGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> using namespace std; int N; int main() { cin >> N; vector<int> arr(N+1); for (int i = 1; i <= N; i++) { cin >> arr[i]; } vector<int> 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<int> 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; } } int ans = INT_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...