Submission #1327986

#TimeUsernameProblemLanguageResultExecution timeMemory
1327986vtnooGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
0 / 100
0 ms332 KiB
#include <bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); i++)
#define R(i, j, k) for(int i = (j); i >= (k); i--)
#define all(x) x.begin(), x.end()
#define sz(a) ((int) a.size())
#define pb push_back
#define fst first
#define snd second
using namespace std;
typedef long long ll;
const int MAXN=2e5+5,INF=1e18;
ll a[MAXN];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;cin>>n;
	L(i,0,n-1)cin>>a[i];
	vector<ll>b(n-1);
	L(i,1,n-1){
		b[i-1]+=a[i]-a[i-1]; 
	}
	vector<ll>pref(n),suff(n);
	L(i,0,n-2){
		pref[i+1]=pref[i];
		if(b[i]<=0)pref[i+1]+=1ll+-1ll*b[i];
	}
	R(i,n-2,0){
		suff[i]=suff[i+1];
		if(b[i]>=0)suff[i]+=b[i]+1ll;
	}
	ll ans=INF;
	L(i,0,n-1){
		ans=min(ans,max(pref[i],suff[i]));
	}
	cout<<ans<<endl;
}

Compilation message (stderr)

Main.cpp:11:26: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   11 | const int MAXN=2e5+5,INF=1e18;
      |                          ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...