Submission #698823

#TimeUsernameProblemLanguageResultExecution timeMemory
698823US3RN4M3Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
87 ms6200 KiB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int mx = 200005;
int A[mx];
ll pref_cost[mx];
ll suff_cost[mx];
int n;
main() {
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> A[i];
	for(int i = 1; i <= n + 1; i++) pref_cost[i] = pref_cost[i - 1] + max(0, 1 + A[i - 1] - A[i]);
	for(int i = n; i >= 0; i--) suff_cost[i] = suff_cost[i + 1] + max(0, 1 + A[i + 1] - A[i]);
	ll ans = 1e18;
	for(int i = 0; i <= n; i++) {
		ans = min(ans, max(pref_cost[i], suff_cost[i]));
	}
	cout << ans << endl;
}

Compilation message (stderr)

Main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...