제출 #758963

#제출 시각아이디문제언어결과실행 시간메모리
758963ridicheGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
83 ms10080 KiB
#include <iostream> #define INT_MAX 9223372036854775807 #define int long long using namespace std; int a[200005]; int cr[200005], cn[200005]; int dr[200005], dn[200005]; signed main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } cn[0] = a[0]; for (int i = 1; i < n; i++) { cn[i] = a[i] + cr[i - 1]; cr[i] = cr[i - 1]; if (cn[i] <= cn[i - 1]) { cr[i] += (cn[i - 1] - cn[i]) + 1; cn[i] = cn[i - 1] + 1; } } dn[n - 1] = a[n - 1]; for (int i = n - 2; i >= 0; i--) { dn[i] = a[i] + dr[i + 1]; dr[i] = dr[i + 1]; if (dn[i] <= dn[i + 1]) { dr[i] += (dn[i + 1] - dn[i]) + 1; dn[i] = dn[i + 1] + 1; } } int r = INT_MAX; for (int i = 0; i < n; i++) { r = min(r, max(cr[i], dr[i])); } cout << r; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...