Operator
Time limit8sMemory limit512 MB
Simulate callers who retry after hanging up, and find the fewest operators so all calls finish within time T.
- Level
Medium7 of 10
- Topics
- Simulation, Binary search, Implementation, Greedy
- Solved
- No attempts yet
Problem
The customer telephone support center of the computer sales company JAG is in chaos. Too many customers ask for support, and they call all the time. The company wants to work out how many operators it needs to handle the situation.
To keep things simple, consider only the following simulation.
There are customers. Customer has id and is described by three integers , , and . An operator needs unit times to support customer . If no operator answers customer within unit times of the moment that customer places the call, the customer hangs up. unit times after hanging up, the customer calls back. If an operator answers at exactly unit times after the call was placed, the call connects; if nobody has answered by that moment, the customer hangs up.
One operator supports only one customer at a time. An operator who finishes a call can answer another call immediately. If more than one customer is waiting, the operator picks the customer with the smallest id.
At the start of the simulation every customer calls the support center at the same time. The simulation succeeds if the support of all customers is finished within unit times. A call that finishes exactly at counts as finished in time.
Compute the minimum number of operators needed for the simulation to succeed.
Input
The input contains multiple datasets. Each dataset has the following format:
N T
M1 L1 K1
.
.
.
MN LN KN
The first line of a dataset contains two positive integers and (, ). is the number of customers in the dataset, and is the time limit of the simulation.
The following lines describe the customers. The -th of those lines contains three integers , , and (, , ).
The end of the input is indicated by a line containing two zeros. That line is not part of any dataset, so do not process it.
Output
For each dataset, print the minimum number of operators needed for the simulation to succeed on its own line.