Submission #828894

#TimeUsernameProblemLanguageResultExecution timeMemory
828894raphaelpGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms300 KiB
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } long long tot = 0; int a = 1, b = N - 2, adda = 0, addb = 0; while (a < b) { while (A[a - 1] - adda < A[a]) { a++; adda = 0; } while (A[b + 1] - addb < A[b]) { b--; addb = 0; } if (a >= b) break; int m = min(A[a - 1] - A[a] + 1 - adda, A[b + 1] - A[b] + 1 - addb); adda += m; addb += m; tot += m; } if (A[a] == A[b] && a == b + 1) tot++; cout << tot; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...