求助求助求助
查看原帖
求助求助求助
316827
Temperature_automata楼主2020/10/9 12:55
#include <iostream>

using namespace std;

const int N = 1e5+5;
struct TICKET{
	int time;//乘坐时间
	int value;//乘坐价格 
}ticket[N];
int n,head,tail,ans;

void pop(int res)
{
	for(int i = res + 1 ; i <= tail ; ++i)
	{
		ticket[i].value = ticket[i-1].value;
		ticket[i].time = ticket[i-1].time;
	}
	tail--;
}

int found_ticket(int price,int times)
{
	int j = head;
	while(head<=tail&&ticket[head].time+45 > times)
	{
		head++;
	}
	while(j<=tail)
	{
		if(ticket[j].value >= price)
			return j;
		j++;
	}
	return 0;
}

int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n;
	bool traffic = 0;//公交or地铁 
	int price;//乘车票价 
	int times;//乘车时间 
	head = 1;
	tail = 0;
	while(n--)
	{
		cin>>traffic>>price>>times;
		if(traffic == 0)
		{
			tail++;
			ticket[tail].time = times;
			ticket[tail].value = price;
			ans+=price;
		}
		else
		{
			int step = found_ticket(price,times);
//			cout<<endl<<head<<endl;
//			cout<<endl<<step<<endl;
			if(step == 0)
				ans += price;
			else
				pop(step);
		}
	}
	cout<<ans;
	return 0;
}

RT

2020/10/9 12:55
加载中...