Submission #984858

#TimeUsernameProblemLanguageResultExecution timeMemory
984858vjudge1Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
25 ms7116 KiB
#include <bits/stdc++.h> #define ft first #define sd second #define pb push_back #define nl "\n" #define int ll typedef long long ll; typedef long double ld; using namespace std; const int N = 1000100; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T = 1; while(T--) { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int dp[n], dp1[n]; dp[0] = 0; dp1[n - 1] = 0; for (int i = 1; i < n; i++) { dp[i] = dp[i - 1]; if (a[i - 1] >= a[i]) { dp[i] += (a[i - 1] - a[i] + 1); } } for (int i = n - 2; i >= 0; i--) { dp1[i] = dp1[i + 1]; if (a[i + 1] >= a[i]) { dp1[i] += (a[i + 1] - a[i] + 1); } } int mn = 1e18; for (int i = 0; i < n; i++) { mn = min( mn, max(dp[i], dp1[i])); } cout << mn; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...