Submission #756778

#TimeUsernameProblemLanguageResultExecution timeMemory
756778otariusGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
79 ms5072 KiB
#include <bits/stdc++.h> using namespace std; #define int ll #define ll long long void solve() { int n; cin >> n; int arr[n + 1], ans = 1e18; for (int i = 1; i <= n; i++) cin >> arr[i]; int pref[n + 1], suff[n + 1]; pref[1] = 0; suff[n] = 0; for (int i = 2; i <= n; i++) { if (arr[i - 1] < arr[i]) pref[i] = pref[i - 1]; else pref[i] = pref[i - 1] + arr[i - 1] - arr[i] + 1; } for (int i = n - 1; i >= 1; i--) { if (arr[i] > arr[i + 1]) suff[i] = suff[i + 1]; else suff[i] = suff[i + 1] + arr[i + 1] - arr[i] + 1; } for (int i = 1; i <= n; i++) { ans = min(ans, max(pref[i], suff[i])); } cout << ans; } int32_t main() { int t = 1; // cin >> t; while (t--) { solve(); cout << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...