제출 #371228

#제출 시각아이디문제언어결과실행 시간메모리
371228cheissmartGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
33 ms4332 KiB
#include <bits/stdc++.h> #define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0); #define F first #define S second #define V vector #define PB push_back #define MP make_pair #define EB emplace_back #define ALL(v) (v).begin(), (v).end() #define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef V<int> vi; const int INF = 1e9 + 7; signed main() { IO_OP; int n; cin >> n; vi a(n); for(int i = 0; i < n; i++) cin >> a[i]; V<ll> p(n), s(n); for(int i = 1; i < n; i++) p[i] = p[i - 1] + max(0, a[i - 1] - a[i] + 1); for(int i = n - 2; i >= 0; i--) s[i] = s[i + 1] + max(0, a[i + 1] - a[i] + 1); ll ans = 1e18; for(int i = 0; i < n; i++) { ans = min(ans, max(s[i], p[i])); } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...