제출 #629932

#제출 시각아이디문제언어결과실행 시간메모리
629932QwertyPiGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
97 ms3064 KiB
#include <bits/stdc++.h> using namespace std; int a[200001]; int l[200001], r[200001]; int cl[200001], cr[200001]; int main(){ int n; cin >> n; for(int i = 0; i < n; i++){ cin >> a[i]; } long long ans = 0; int l = 1, r = n - 1; while(l <= r){ int d = max(0, min((a[l - 1] + 1) - a[l], (a[r + 1] + 1) - a[r])); a[l - 1] -= d; a[r + 1] -= d; ans += d; if(a[l] > a[l - 1]) l++; if(a[r] > a[r + 1]) r--; } if(l == r + 1 && a[l] == a[r]) ans++; cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...