#include <bits/stdc++.h>
using namespace std;
const int MAXN=1001;
struct ticket
{
int price,time,used;
}q[MAXN];
int head, tail, n, cost;
int main()
{
cin>>n;
for (int i=0;i<n;i++)
{
int kind,price,time;
cin>>kind>>price>>time;
if (kind==0)
{
cost+=price;
q[tail].time=time+45;
q[tail++].price=price;
}
else
{
while (head<tail&&q[head].time<time)
{
head++;
}
bool found=false;
for (int j=head;j<tail;j++)
{
if (q[j].price>=price&&q[j].used==0)
{
found=true;
q[j].used=1;
break;
}
}
if (!found)
cost+=price;
}
}
cout<<cost<<endl;
return 0;
}
本题只得了30分,错误部分显示:Runtime Error. Received signal 11: Segmentation fault with invalid memory reference.不知道是哪里出了问题。麻烦指出错误,并给出正确改正方案。谢谢!