제출 #1251684

#제출 시각아이디문제언어결과실행 시간메모리
1251684inkvizytorGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
15 ms5080 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<ll> a (n, 0); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<ll> sp (n, 0), ss (n, 0); for (int i = 1; i < n; i++) { sp[i] = sp[i-1]+max(0ll, a[i-1]-a[i]+1); } for (int i = n-2; i >= 0; i--) { ss[i] = ss[i+1]+max(0ll, a[i+1]-a[i]+1); } ll w = 1e18; for (int i = 0; i < n; i++) { w = min(w, max(sp[i],ss[i])); } cout << w << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...