제출 #534824

#제출 시각아이디문제언어결과실행 시간메모리
534824Paul_Liao_1457Growing Vegetables is Fun 4 (JOI21_ho_t1)C++14
0 / 100
0 ms332 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=pre[n]; FOR(i,2,n+2){ if(pre[i-1]>=suf[i]){ ans=min(ans,pre[i-1]); } } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...