제출 #679956

#제출 시각아이디문제언어결과실행 시간메모리
679956redstonegamer22Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
91 ms6888 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { int n; cin >> n; vector<int> a(n); for(auto &e : a) cin >> e; vector<int> dpl(n), dpr(n); for(int i = 0; i < n; i++) { if(i == 0) dpl[i] = 0; else { if(a[i] > a[i - 1]) dpl[i] = dpl[i - 1]; else dpl[i] = dpl[i - 1] + (a[i - 1] + 1 - a[i]); } } for(int i = n - 1; i >= 0; i--) { if(i == n - 1) dpr[i] = 0; else { if(a[i] > a[i + 1]) dpr[i] = dpr[i + 1]; else dpr[i] = dpr[i + 1] + (a[i + 1] + 1 - a[i]); } } int ans = (1LL << 50); for(int i = 0; i < n; i++) { ans = min(ans, max(dpl[i], dpr[i])); } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...