제출 #420818

#제출 시각아이디문제언어결과실행 시간메모리
420818Harry464Growing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
110 ms5316 KiB
#include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <utility> using namespace std; typedef long long ll; int main() { ll n; cin >> n; vector <ll> a(n); for (int i = 0; i < n; i++) cin >> a[i]; ll uk = 0; vector <ll> potl(n); for (int i = 0; i < n - 1; i++){ potl[i] = uk; ll tren = a[i] + 1 - a[i+1]; if (tren > 0) uk += tren; } potl[n-1] = uk; uk = 0; ll rjes = potl[n-1]; for (int i = n - 1; i >= 1; i--){ ll tren = a[i] + 1 - a[i-1]; if (tren > 0) uk += tren; rjes = min(rjes, max(uk, potl[i-1])); } cout << rjes; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...