제출 #828895

#제출 시각아이디문제언어결과실행 시간메모리
828895raphaelpGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
70 ms3020 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...