제출 #394319

#제출 시각아이디문제언어결과실행 시간메모리
394319Aryan_RainaGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
35 ms6980 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define ar array const int INF = 1e17; const int MOD = 998244353; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(); int n; cin>>n; vector<int> a(n); for (int &i : a) cin>>i; vector<int> pf(n, 0), sf(n, 0); for (int i = 1; i < n; i++) pf[i] = pf[i-1] + max(a[i-1]-a[i]+1, 0LL); for (int i = n-2; i >= 0; i--) sf[i] = sf[i+1] + max(a[i+1]-a[i]+1, 0LL); int ans = INF; for (int i = 0; i < n; i++) { // keep pairing stuff on left and right and [l,r]++ ans = min(ans,max(pf[i], sf[i])); } cout<<ans<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...