Submission #532474

#TimeUsernameProblemLanguageResultExecution timeMemory
532474alanlGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
25 ms6928 KiB
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define rep(X, a,b) for(int X=a;X<b;++X)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (int)(a).size()
#define NL "\n"
using namespace std;
typedef pair<long long,long long> pll;
typedef pair<int,int> pii;
typedef long long ll;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << "," << p.second << ')'; }
template<typename A> ostream& operator<<(ostream &os, const vector<A> &p){
	for(const auto &a:p)
		os << a << " ";
	os << "\n";
	return os;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	vector<ll> num(n), lft(n), mx(n);
	rep(i,0,n) cin>>num[i];
	lft[0]=0;
	ll cur=0;
	rep(i,1,n){
		if(num[i]<=num[i-1]){
			cur+=num[i-1]-num[i]+1;
		}
		lft[i]=cur;
	}
	//cout<<lft;
	cur=0;
	ll ans=lft[n-1];
	for(int i=n-2;i>=0;--i){
		if(num[i]<=num[i+1]) cur+=num[i+1]-num[i]+1;
		ans=min(ans, max(lft[i], cur));
		//cout<<cur<<NL;
	}
	cout<<ans<<NL;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...