Submission #574256

#TimeUsernameProblemLanguageResultExecution timeMemory
574256benson1029Growing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
1 ms312 KiB
#include<bits/stdc++.h>
using namespace std;

int n;
long long a[200005];
long long ans[200005], ans2[200005];

int main() {
	cin >> n;
	for(int i=1; i<=n; i++) {
		cin >> a[i];
	}
	for(int i=n; i>=1; i--) {
		a[i] -= a[i-1];
	}
	for(int i=1; i<=n; i++) {
		ans[i] = ans[i-1];
		if(a[i] <= 0) {
			ans[i] += 1 - a[i];
		}
	}
	for(int i=n-1; i>=0; i--) {
		ans2[i] += ans2[i+1];
		if(a[i+1] >= 0) {
			ans2[i] += 1 + a[i+1];
		}
	}
	long long o = 1e18;
	for(int i=0; i<=n; i++) o = min(o, ans[i] + ans2[i]);
	cout << o << "\n";
} 
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...