Submission #384078

#TimeUsernameProblemLanguageResultExecution timeMemory
384078AntekbGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
100 ms6252 KiB
#include<bits/stdc++.h>

#define st first
#define nd second
#define pb(x) push_back(x)
#define pp(x) pop_back(x)
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define rev(x) reverse(all(x))
#define sor(x) sort(all(x))
#define sz(x) (int)(x).size()
#define rsz(x) resize(x)

using namespace std;

///~~~~~~~~~~~~~~~~~~~~~~~~~~

void debug(){cerr<<"\n";}
template <typename H, typename... T>
void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);}
#define deb(x...) cerr<<#x<<" = ";debug(x);

///~~~~~~~~~~~~~~~~~~~~~~~~~

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii > vii;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef string str;

#define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

const int N=2e5+5, INF=1e9+5, mod=1e9+7;
int tab[N];
ll pref[N], suf[N];
int main(){
	//BOOST;
	int n;
	cin>>n;
	for(int i=0; i<n; i++)cin>>tab[i];
	for(int i=1; i<n; i++)pref[i]=pref[i-1]+max(tab[i-1]-tab[i]+1, 0);
	for(int i=n-2; i>=0; i--)suf[i]=suf[i+1]+max(tab[i+1]-tab[i]+1, 0);
	ll ans=1e18;
	for(int i=0; i<n; i++){
		ans=min(ans, max(pref[i], suf[i]));
	}
	cout<<ans;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...