제출 #716453

#제출 시각아이디문제언어결과실행 시간메모리
716453immccn123Growing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
126 ms3800 KiB
#include <iostream> using namespace std; typedef long long ll; ll df[200006]; ll N, i, v = 0, L, R, ans = 0, d, tp; int main() { cin >> N; for (int i = 1; i <= N; i++) { cin >> tp; df[i] = tp - v; v = tp; } L = 2; R = N; while (L <= R) { if (df[L] > 0) L++; else if (df[R] < 0) R--; else if (L == R) { if (df[L] == 0) ans++; L++; } else { d = min(-df[L] + 1, df[R] + 1); ans += d; df[L] += d; df[R] -= d; } } cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...