제출 #710656

#제출 시각아이디문제언어결과실행 시간메모리
710656yellowtoadGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
90 ms3832 KiB
#include <iostream> using namespace std; long long n, a[200010], ans, ll, rr, l, r, tmp; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; l = 1; r = n; ll = max(0LL,a[l]-a[l+1]+1); rr = max(0LL,a[r]-a[r-1]+1); while (l < r) { tmp = min(ll,rr); ll -= tmp; rr -= tmp; ans += tmp; if (ll == 0) { l++; ll = max(0LL,a[l]-a[l+1]+1); } if (rr == 0) { r--; rr = max(0LL,a[r]-a[r-1]+1); } } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...