제출 #1323375

#제출 시각아이디문제언어결과실행 시간메모리
1323375khanhphucscratchGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
22 ms5112 KiB
#include<bits/stdc++.h> #define int long long using namespace std; int a[200005], prefix[200005], suffix[200005]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin>>n; for(int i = 1; i <= n; i++) cin>>a[i]; for(int i = n; i >= 1; i--) a[i] -= a[i-1]; for(int i = 1; i <= n; i++) prefix[i] = prefix[i-1] + max(-a[i]+1, 0ll); for(int i = n; i >= 1; i--) suffix[i] = suffix[i+1] + max(a[i]+1, 0ll); int ans = 1e18; for(int i = 0; i <= n; i++) ans = min(ans, max(prefix[i], suffix[i+1])); cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...