Submission #756771

#TimeUsernameProblemLanguageResultExecution timeMemory
756771otariusGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long void solve() { int n; cin >> n; int arr[n + 1]; 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; } int ans = min(pref[n], suff[1]); for (int i = 2; i <= n; i++) { ans = min(ans, max(pref[i], suff[i])); } cout << ans; } int 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...