제출 #803037

#제출 시각아이디문제언어결과실행 시간메모리
803037starchanGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
21 ms6996 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define in pair<int, int> #define f first #define s second #define pb push_back #define pob pop_back #define INF (int)1e17 #define MX (int)3e5+5 #define fast() ios_base::sync_with_stdio(false); cin.tie(NULL) signed main() { fast(); int n; cin >> n; vector<int> a(n); for(int i = 0; i < n; i++) cin >> a[i]; for(int i = n-1; i > 0; i--) a[i]-=a[i-1]; vector<int> pref(n), suff(n+1); pref[0] = 0; for(int i = 1; i < n; i++) { pref[i] = pref[i-1]; if(a[i] > 0) continue; pref[i]+=(1-a[i]); } suff[n] = 0; for(int i = n-1; i > 0; i--) { suff[i] = suff[i+1]; if(a[i] < 0) continue; suff[i]+=(1+a[i]); } int ans = INF; for(int k = 1; k <= n; k++) ans = min(max(pref[k-1], suff[k]), ans); cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...