Submission #1099261

#TimeUsernameProblemLanguageResultExecution timeMemory
1099261DangKhoizzzzGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
23 ms6296 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int maxn = 2e5 + 7; int n , a[maxn] ; ll precnt[maxn] , sufcnt[maxn]; void solve() { cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n; i++) { precnt[i] = precnt[i-1]; if(a[i] <= a[i-1]) { precnt[i] += a[i-1] - a[i] + 1; } } for(int i = n; i >= 1; i--) { sufcnt[i] = sufcnt[i+1]; if(a[i] <= a[i+1]) { sufcnt[i] += a[i+1] - a[i] + 1; } } ll ans = 1e18; for(int i = 1; i <= n; i++) { ans = min(ans , max(precnt[i] , sufcnt[i])); } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...