#7. 【CSP-J 2019 T2】 公交换乘 (Bus Transfer)
【CSP-J 2019 T2】 公交换乘 (Bus Transfer)
Description
City B, a famous city, has introduced a preferential plan for changing from subways to buses in order to encourage people to use public transportation:
- After taking the subway once, you will get a discount ticket, valid for minutes. You can use this ticket during its valid period to take a bus whose fare does not exceed the ticket's fare for free. A valid period means that the difference between the time you take the bus and the time you take the subway is less than or equal to minutes, which is: .
- The discount ticket can be stacked up to multiple tickets, which means you can take the subway several times and then use one of the tickets to take the bus.
- When taking the bus, if you can use a ticket, you will definitely use it. If there are multiple tickets that meet the conditions, you will use the earliest one.
Given a list of recent public transportation used by Xiaoxuan, help him calculate how much he needs to pay.
Input Format
The first line contains a single integer , which is the number of rides in the list.
Each of the following lines contains integers, seperated by spaces. The st integer in the th line represents the type of transportation that Xiaoxuan used, where means the subway, and means the bus. The nd integer represents the of the th ticket. The rd integer represents the time when he used this transportation in minutes (calculated from ).
It is guaranteed that the list will be given in increasing order of the time when Xiaoxuan used the ride, and no two records will appear in the same minute.
Output Format
Print a single line containing how much Xiaoxuan needs to pay.
6
0 10 3
1 5 46
0 12 50
1 3 96
0 5 110
1 6 135
36
First, you took a subway at time for yuan.
Next, you took a bus at time . You will use the ticket obtained from the first ride, so you don't have to pay.
The third line shows that you took a subway at time for a cost of yuan.
In the fourth ride, you took a bus at time , and since it has been more than minutes since the last time you took the subway, you will have to pay yuan.
In the fifth ride, you took a subway at time for a cost of yuan.
At the last ride, you took the bus at time , but you can't use the last ticket because the bus's fare is higher than the fare of your only valid ticket . So you have to pay yuan.
In total, you'll need to pay yuan.
6
0 5 1
0 20 16
0 7 23
1 18 31
1 4 38
1 7 68
32
First, you took a subway at time for yuan.
Next, you took another subway at time for yuan.
The third line shows that you took another subway at time for a cost of yuan.
In the fourth ride, you took a bus at time with a cost of yuan, and the only valid ticket is the one you got after taking the second subway, so you will use it to take this bus without any cost.
In the fifth ride, you took a bus at time with a cost of yuan. You have two valid tickets to use so you will use the first one which you got from taking the subway at time .
At the last ride, you took the bus at time , and you can use the last ticket to avoid paying yuan.
In total, you'll need to pay yuan.
Constraints
For of the data, .
For another of the data, , and all tickets' prices are equal.
For another of the data, , and all tickets' prices are equal.
For of the data, .