Submission #532799

#TimeUsernameProblemLanguageResultExecution timeMemory
532799sam571128Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
25 ms8516 KiB
#include <bits/stdc++.h> #define int long long #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; signed main(){ fastio int n; cin >> n; int arr[n], diff[n], pref[n] = {}, suff[n+1] = {}; for(auto &x : arr) cin >> x; for(int i = 1;i < n;i++){ diff[i] = arr[i] - arr[i-1]; } int ans = 1e18; for(int i = 1;i < n;i++){ pref[i] = (pref[i-1] + (diff[i] < 1 ? 1-diff[i] : 0)); } for(int i = n-1;i >= 0;i--){ suff[i] = (suff[i+1] + (diff[i] > -1 ? diff[i]+1 : 0)); } for(int i = 0;i < n;i++){ ans = min(ans,max(pref[i],suff[i+1])); } cout << ans << "\n"; } //-10 32 51 -81 87 -62 56
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...