제출 #1016150

#제출 시각아이디문제언어결과실행 시간메모리
1016150rsinventorGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
26 ms7012 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector <ll> vll; typedef vector<bool> vb; typedef vector <string> vs; typedef vector<char> vc; typedef pair<int, int> pii; typedef vector <pii> vpii; #define all(a) (a).begin(), (a).end() #define pb push_back #define endl "\n" #define int ll signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); for(int i = 0; i < n; i++) { cin >> a[i]; } vector<int> up(n); vector<int> down(n); for(int i = 1; i < n; i++) { up[i] = up[i-1] + max(0ll, (a[i-1] - a[i] + 1)); } for(int i = n-2; i >= 0; i--) { down[i] = down[i+1] + max(0ll, (a[i+1] - a[i] + 1)); } int res = max(up[0], down[0]); for(int i = 0; i < n; i++) { res = min(res, max(up[i], down[i])); } cout << res << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...