Submission #534828

#TimeUsernameProblemLanguageResultExecution timeMemory
534828Paul_Liao_1457Growing Vegetables is Fun 4 (JOI21_ho_t1)C++14
100 / 100
28 ms8496 KiB
// 還要更強 #include<iostream> #include<queue> #include<set> #include<map> #include<iomanip> #include<math.h> #include<cstring> #include<stack> #include<string.h> #include<random> #include<algorithm> #include<vector> #define ll long long #define FOR(i,a,b) for(int i=a;i<b;i++) #define REP(i,a,b) for(int i=a;i>=b;i--) #define INF (ll)(8e18) #define pb push_back #define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace std; ll b[200005],a[200005],pre[200005],suf[200005]; signed main(){ AC; int n; cin>>n; FOR(i,1,n+1) cin>>a[i]; FOR(i,2,n+1){ b[i]=a[i]-a[i-1]; } FOR(i,2,n+1){ pre[i]=pre[i-1]; if(b[i]<=0) pre[i]+=(1-b[i]); } REP(i,n,2){ suf[i]=suf[i+1]; if(b[i]>=0) suf[i]+=(b[i]+1); } ll ans=min(suf[2],pre[n]); FOR(i,2,n+2){ ans=min(ans,max(suf[i],pre[i-1])); } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...