P5661 公交换乘
#include<iostream>
#include<cstdio>
using namespace std;
class car {
public:
int p;
int time;
car *next;
};
int main()
{
int n;
car *head = new car;
car *node = head;
int a, b, c, sum(0);
scanf("%d", &n);
head->next = NULL;
while (n > 0) {
scanf("%d %d %d", &a, &b, &c);
if (a == 0)
{
node->next = new car;
node = node->next;
node->p = b;
node->time = c;
sum += b;
node->next = NULL;
}
else
{
node = head;
while (node->next != NULL)
{
if ((c - (node->next)->time) > 45)
{
(*node).next = (*node->next).next;
}
else
{
node = node->next;
}
}
node = head;
while (node->next != NULL)
{
if ((node->next)->p >= b)
{
(*node).next = (*node->next).next;
if (node->next != NULL)
break;
else
sum -= b;
}
else
{
node = node->next;
}
}
if (node->next == NULL)
{
sum += b;
}
}
--n;
}
printf("%d\n", sum);
sum = 0;
}