Submission #1281955

#TimeUsernameProblemLanguageResultExecution timeMemory
1281955dhuyyyyGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
18 ms5140 KiB
#include<bits/stdc++.h> #define fi first #define se second #define int long long using namespace std; using ll = long long; using ii = pair<int, int>; using aa = array<int,3>; const int N = 5e5+5; int n, ans = (int)1e18, timer, cur, pos, mx; int a[N], pre[N], suf[N]; signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); cin >> n; for (int i = 1; i <= n; i++){ cin >> a[i]; } for (int i = 2; i <= n; i++){ pre[i] = pre[i-1]; if (a[i-1] >= a[i]) pre[i] += (a[i-1] + 1 - a[i]); } for (int i = n - 1; i >= 1; i--){ suf[i] = suf[i + 1]; if (a[i + 1] >= a[i]) suf[i] += (a[i + 1] + 1 - a[i]); } for (int i = 1; i <= n; i++) ans = min(ans,max(pre[i],suf[i])); cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...