不知道为啥Re了……
看出wa也说一下吧,谢谢。
#include <bits/stdc++.h>
using namespace std;
class node
{
public:
int t, m;//记录优惠票的时间和钱数
};
deque<node> q;//记录优惠票
stack<node> q_out;//排查可用优惠票的时候,推出到这里
int n, ans;
int main()
{
cin >> n;
for(int i = 1; i <= n; i++)
{
bool f;//记录公交车or地铁
int m, t;//记录钱、时间
cin >> f>> m >> t;
if(!f)//地铁
{
node next;//建立优惠票
next.t = t;
next.m = m;
q.push_back(next);//推入优惠票
ans += m;//付钱
}
else if(f)//公交
{
while(t - q.front().t > 45)//超时,不可能再次可用
{
q.pop_front();//弹出不可用的优惠票
}
while(q.size())//q不为空
{
if(q.front().m <= m)//可用
{
q.pop_front();//使用,弹出
goto ok;
}
else
{
q_out.push(q.front());//放到临时栈里
q.pop_front();
}
}
ans += m;//没法用优惠券,付钱
ok:
while(q_out.size())//把临时栈里的优惠券放回去
{
q.push_front(q_out.top());
q_out.pop();
}
}
}
cout << ans;
return 0;
}