Submission #533310

#TimeUsernameProblemLanguageResultExecution timeMemory
533310star_platinumGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
27 ms8524 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; #pragma GCC optimize("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define mikumywaifu ios_base::sync_with_stdio(0) #define mudrockmywaifu cin.tie(0) #define pb push_back #define ss second #define ff first #define mem(i,j) memset(i,j,sizeof(i)) #define pii pair<int,int> #define pll pair<long,long> #define lowbit(x) x&-x const int INF =0x3F3F3F3F; const ll LINF=4611686018426387903; ll gcd(ll a,ll b){ if(b==0) return a; a%=b; return gcd(b,a); } void debug(){ cout<<"DEBUG :"; cout<<"\n"; } /*-----------------------------------------*/ signed main(){ mikumywaifu; mudrockmywaifu; int n; cin>>n; vector<ll>a(n+1),b(n+1); for(int i=0;i<n;i++){ cin>>a[i]; b[i]=a[i]; } vector<ll> l(n+1),r(n+1); l[0]=0,r[n-1]=0; for(int i=1;i<n;i++){ l[i]=l[i-1]; l[i]+=(a[i]>a[i-1])?0:a[i-1]-a[i]+1; } for(int i=n-2;i>=0;i--){ r[i]=r[i+1]; r[i]+=(b[i]>b[i+1])?0:b[i+1]-b[i]+1; } ll ans=1e18; for(int i=0;i<n;i++){ ans=min(ans,max(l[i],r[i])); } cout<<ans<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...