跳到正文

题解

题解:AT_abc446_c [ABC446C] Omelette Restaurant

wanghuwang666约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年2月22日
收录
2026年7月13日
更新
2026年11月15日
篇幅
约 1 分钟

版本

  1. v1当前

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

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

  • 对于第一种操作:在队尾插入 AiA_i 个 ii。
  • 对于第二种操作:弹出 BiB_i 个队头。
  • 对于第三种操作:在队头把所有超时的弹出。
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;
}
原文