既然都要遍历了,再来个链表优化又如何
2025-10-02 22:27:40
发布于:广东
1阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
int n,sum=0;
struct node
{
int price,time;
};
list<node> q;
int main()
{
bool type;
int p,t;
cin >> n;
while (n--)
{
cin >> type >> p >> t;
while (!q.empty() && t-q.front().time>45)
q.pop_front();
if (type==0)
{
sum+=p;
q.push_back({p,t});
}
else
{
bool can=0;
for (auto i=q.begin();i!=q.end();i++)
{
if (i->price>=p)
{
q.erase(i),can=1;
break;
}
}
if (!can) sum+=p;
}
}
cout << sum;
return 0;
}
这里空空如也





有帮助,赞一个