题解:AT_abc446_c [ABC446C] Omelette Restaurant

· · 题解

这么简单的 C 题再不写题解就没机会了。

用队列维护,一个鸡蛋只用记录它来的天数就全都代表完了。

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long

using namespace std;

int a[200005];
int b[200005];
void solve(){
    int n,d;
    cin>>n>>d;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)cin>>b[i];
    queue<int> q;
    for(int i=1;i<=n;i++){
        while(a[i]--)q.push(i);//                第一种操作
        while(b[i]--)q.pop();//                  第二种操作
        while(q.size()&&q.front()+d<=i)q.pop();//第三种操作
    }
    cout<<q.size()<<endl;
}
int main(){
    int T;
    cin>>T;
    while(T--){
        solve();
    }
    return 0;
}