0pts求调
查看原帖
0pts求调
963648
AidenWang楼主2024/10/19 22:27

RT,代码如下

#include <iostream>
#define q_empty (tail-head>=0)
using namespace std;
const int MAXN=1e5+5;
struct tkt
{
	int time,price;
	bool used;
}q[MAXN];
int head=1,tail=0,n,tp,pr,tm,ans;  // q,head,tail -> stack
int main()
{
	cin >> n;
	for(int i = 1;i <= n;i ++)
	{
		cin >> tp >> pr >> tm;
		if(tp==0)
		{
			ans+=pr;
			q[++tail] = tkt{tm,pr,false};
		}else
		{
			bool fd=false;
			while(head<=tail && tm-q[head].time>45 || q[head].used)
			head++;
			if(!q_empty)
			{
				for(int j = head;j <= tail;j ++)
				if(q[j].price>=pr && (!q[j].used))
				{fd=true;q[j].used=true;
//				printf("fd=true,j=%d (at %d)",j,i);
				break;}
				if(!fd) ans+=pr;
			}
			else ans+=pr;
		}
	}
	cout << ans << endl;
	return 0;
}
2024/10/19 22:27
加载中...