제출 #807045

#제출 시각아이디문제언어결과실행 시간메모리
807045caganyanmazGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 ms336 KiB
#include <bits/stdc++.h> using namespace std; constexpr static int MXSIZE = 2e5; int n, v[MXSIZE], dp[MXSIZE+1][2]; // Increasing, decreasing int main() { cin >> n; for (int i = 0; i < n; i++) cin >> v[i]; for (int i = 2; i <= n; i++) dp[i][0] = dp[i-1][0] + max(0, 1 + v[i-2] - v[i-1]); for (int i = n-2; i >= 0; i--) dp[i][1] = dp[i+1][1] + max(0, 1 + v[i+1] - v[i]); int mn = min(dp[n][0], dp[0][1]); for (int i = 1; i < n-1; i++) { int l = v[i-1] + dp[i][0]; int r = v[i+1] + dp[i+1][1]; int c = v[i] + dp[i][0] + dp[i+1][1]; mn = min(mn, max(dp[i][0], dp[i+1][1]) + max({c-1, r, l}) - c + 1); } cout << mn << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...