제출 #1219134

#제출 시각아이디문제언어결과실행 시간메모리
1219134trimkusGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
48 ms5056 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;


int main() {
	int n;
	cin >> n;
	vector<ll> a(n);
	for (auto& x : a) cin >> x;
	vector<ll> ps(n), sf(n);
	for (int i = 1; i < n; ++i) {
		ps[i] = ps[i - 1];
		if (a[i - 1] >= a[i]) {
			ps[i] += a[i - 1] - a[i] + 1;
		}
	}
	for (int i = n - 2; i >= 0; --i) {
		sf[i] = sf[i + 1];
		if (a[i + 1] >= a[i]) {
			sf[i] += a[i + 1] - a[i] + 1;
		}
	}
	ll res = LLONG_MAX;
	for (int i = 0; i < n; ++i) {
		res = min(res, max(sf[i], ps[i]));
	}
	cout << res << "\n";
	
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...