제출 #936887

#제출 시각아이디문제언어결과실행 시간메모리
936887the_coding_poohGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
66 ms6996 KiB
#include <bits/stdc++.h> #define uwu return 0; using namespace std; const int SIZE = 2e5 + 5; int N; const long long INF = 1e18 + 5; long long from_f[SIZE], from_e[SIZE], h[SIZE]; int main(){ cin >> N; for (int i = 1; i <= N;i++){ cin >> h[i]; } for (int i = 1; i <= N;i++){ from_f[i] = from_f[i - 1] + max(0LL, h[i - 1] - h[i] + 1); //cout << from_f[i] << '\n'; } for (int i = N; i >= 1;i--){ from_e[i] = from_e[i + 1] + max(0LL, h[i + 1] - h[i] + 1); } long long ans = INF; for (int i = 1; i <= N;i++){ ans = min(ans, max(from_f[i], from_e[i])); } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...