제출 #936846

#제출 시각아이디문제언어결과실행 시간메모리
936846jcelinGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
27 ms11088 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 1e6 + 7; const ll INF = 1e18 + 7; const int logo = 20; const int off = 1 << logo; ll pf[MAXN], arr[MAXN], sf[MAXN]; void solve(){ int n; cin >> n; for(int i=1; i<=n; i++) cin >> arr[i]; for(int i=2; i<=n; i++){ pf[i] = pf[i - 1]; if(arr[i] <= arr[i - 1]) pf[i] += 1 + arr[i - 1] - arr[i]; } for(int i=n-1; i; i--){ sf[i] = sf[i + 1]; if(arr[i] <= arr[i + 1]) sf[i] += 1 + arr[i + 1] - arr[i]; } ll ans = INF; for(int i=1; i<=n; i++) ans = min(ans, max(pf[i], sf[i])); cout << ans << "\n"; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int tt = 1; //cin >> tt; while(tt--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...