Submission #908862

#TimeUsernameProblemLanguageResultExecution timeMemory
908862vjudge1Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
66 ms6996 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll n;
	cin>>n;
	vector<ll>vegetales(n);
	for(ll i=0;i<n;i++){
		cin>>vegetales[i];
	}
	vector<ll>a(n);
	a[0]=0;
	for(ll i=1;i<n;i++){
		a[i]=a[i-1]+max(0LL,vegetales[i-1]-vegetales[i]+1);
	}
	reverse(vegetales.begin(),vegetales.end());
	vector<ll>b(n);
	b[0]=0;
	for(ll i=1;i<n;i++){
		b[i]=b[i-1]+max(0LL,vegetales[i-1]-vegetales[i]+1);
	}
	ll ans=1e18;
	reverse(b.begin(),b.end());
	for(ll i=0;i<n;i++){
		ans=min(ans,max(a[i],b[i]));
	}
	cout<<ans<<"\n";
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...