0分,前十二个点WA,后八个点TLE,求助
查看原帖
0分,前十二个点WA,后八个点TLE,求助
519936
Lqz114514楼主2023/5/4 13:15
#include <bits/stdc++.h>
using namespace std;
struct clc{
	int price,ti;
};
queue <clc> coupons;//优惠券队列
int main()
{
	int n,tot=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int op,Price,time;
		cin>>op>>Price>>time;
		if(op==0)//乘地铁 
		{
			clc coupon;	
        coupon.price=Price;	
        coupon.ti=time;
			coupons.push(coupon);//将优惠券放入队列中 
			tot+=Price;//地铁必定支付票价 
		}
		if(op==1)//乘公交 
		{
			bool used=false;//假定不能使用 
			for(int j=0;j<coupons.size();j++)
			{
				clc tmp=coupons.front();
				if(Price<=tmp.price&&tmp.ti-time<=45)
				{
					coupons.pop();
					used=true;//符合条件,使用优惠券 
					break;
				}
				if(tmp.ti-time>45) coupons.pop();//过期的优惠券就扔掉 
			}
			if(used) continue;//如果能使用,不要钱
			else tot+=Price;//不能使用,支付票价 
		}
	}
	cout<<tot;
}
2023/5/4 13:15
加载中...