Submission #807053

#TimeUsernameProblemLanguageResultExecution timeMemory
807053caganyanmazGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> #define int int64_t using namespace std; constexpr static int MXSIZE = 2e5; int n, v[MXSIZE], dp[MXSIZE+1][2]; // Increasing, decreasing int32_t 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<int>(0, 1 + v[i-2] - v[i-1]); for (int i = n-2; i >= 0; i--) dp[i][1] = dp[i+1][1] + max<int>(0, 1 + v[i+1] - v[i]); //int mn = min(dp[n][0], dp[0][1]); int mn = INT_MAX; for (int i = 0; i < n; i++) { int l = i > 0 ? (v[i-1] + dp[i][0]) : 0; int r = i < (n-1) ? v[i+1] + dp[i+1][1] : 0; 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...