Submission #1117479

#TimeUsernameProblemLanguageResultExecution timeMemory
1117479secretwood01Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
31 ms10192 KiB
// Find the max number of rounds you need for each prefix, and each suffix, then for each position, check the max of the prefix and suffix. #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...