제출 #508891

#제출 시각아이디문제언어결과실행 시간메모리
508891ITOGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++11
0 / 100
1 ms300 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int a[200001]; int main() { int n; ll c = 0, x; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } int j = 0, k = n - 1; while (1) { while (j < k && a[j] < a[j + 1]) { j++; } while (k > j && a[k] < a[k - 1]) { k--; } if (j + 1 == k) { c++; j++; } if (j == k) { break; } x = min(a[j] - a[j + 1], a[k] - a[k + 1]) + 1; c += x; a[j] -= x; a[k] -= x; } cout << c << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...