Bus
Time limit2sMemory limit256 MB
Pick one rider each day to pay the full rent so the largest overpayment above each rider's fair share is as small as possible.
- Level
Medium7 of 10
- Topics
- Graph, Binary search
- Solved
- No attempts yet
Problem
A company runs one shuttle bus that takes employees home at the end of each day. To ride it, an employee registers online in advance. Every morning the company checks that the bus capacity is not exceeded and posts the list of riders for that day.
The rent of the bus is per day, and it does not depend on how many people ride. By a rule everyone accepted, exactly one of the people on the bus that day pays the whole rent to the driver. The name of the person who pays is announced daily as well.
Write a program that picks the person who pays on each day so that the assignment is fair in the sense defined below.
Let be the lists of employees on the bus on day 1 through day , and let be the size of . If an employee rides the bus on days , the correct share of is
If is chosen to pay the rent times, actually pays , which is more than the correct share. The unfairness of an assignment is the maximum of over all employees . An assignment with the smallest unfairness is a fair assignment.
Input
The input holds several test cases. The first line of each test case has three positive integers , and , where is the number of employees, is the number of days, and is the daily rent of the bus (, ).
The next lines describe one day each. Every such line starts with the number of employees on the bus that day, followed by that many employee IDs, each an integer between and . No ID appears twice on the same line, and at least one employee rides on every day. To keep the arithmetic simple, is chosen so that the share of one employee is an integer on every day.
The last line of the input is 0 0 0 and must not be processed.
Output
For each test case, print the unfairness of a fair assignment on its own line.