题解:AT_abc379_d [ABC379D] Home Garden

· · 题解

一道大水题,暴力就能过,数据超弱,配当D吗,开一个a数组,每种一个便cnt++,移除时head++就行

#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[200005],cnt,head=1;
signed main(){
    int q;
    cin>>q;
    while(q--){
        int opt;
        cin>>opt;
        if(opt==1){
            a[++cnt]=0;
        }
        if(opt==2){
            int t;
            cin>>t;
            for(int i=head;i<=cnt;i++){
                a[i]+=t;
            }
        }
        if(opt==3){
            int h,ans=0;
            cin>>h;
            for(int i=head;i<=cnt;i++){
                if(a[i]>=h){
                    head++;
                    ans++;
                }
            }
            cout<<ans<<'\n';
        }
    }
}