제출 #1053734

#제출 시각아이디문제언어결과실행 시간메모리
1053734dpsaveslivesGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
53 ms7328 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int MAXN = 2e5+5; ll arr[MAXN],f[MAXN],g[MAXN]; ll INF = 1e18; int main() { int N; cin >> N; for(int i = 1;i<=N;++i) cin >> arr[i]; for(int i = 1;i<=N;++i){ f[i] = f[i-1]+max(arr[i-1]-arr[i]+1,0ll); } for(int i = N;i>=0;--i){ g[i] = g[i+1]+max(arr[i+1]-arr[i]+1,0ll); } ll ans = INF; for(int i = 1;i<=N;++i){ ans = min(max(f[i],g[i]),ans); } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...