Submission #1146529

#TimeUsernameProblemLanguageResultExecution timeMemory
1146529NomioGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
100 / 100
15 ms5740 KiB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int a[n];
	ll b[n - 1];
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for(int i = 0; i < n - 1; i++) {
		b[i] = a[i] - a[i + 1];
	}
	ll c[n] {}, d[n] {};
	for(int i = 0; i < n - 1; i++) {
		c[i + 1] = c[i] + max(0LL, 1 + b[i]);
	}
	for(int i = n - 2; i >= 0; i--) {
		d[i] = d[i + 1] + max(0LL, 1 - b[i]);
	}
	ll ans = 1e18;
	for(int i = 0; i < n; i++) {
		ans = min(ans, max(c[i], d[i]));
	}
	cout << ans << '\n';
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...