Assigning Work with Penalty Points
Time limit3sMemory limit256 MB
Distribute K extra job slots among N employees to complete as many of M jobs as possible, where each employee handles only listed jobs.
- Level
Medium6 of 10
- Topics
- Graph
- Solved
- No attempts yet
Problem
Kangho's company has employees and jobs to finish. Employees are numbered 1 to , and jobs are numbered 1 to .
Each employee has a fixed list of jobs they can do. Every job is handled by exactly one person, and an employee normally takes only one job from that list. An employee who received penalty points last month takes at most jobs.
Suppose there are three employees, and last month Minho (employee 1) received 2 points, Jaepil (employee 2) received 1 point, and Juhyun (employee 3) received 0 points. Then Minho takes at most 3 jobs, Jaepil at most 2 jobs, and Juhyun at most 1 job.
No employee knows their own score. Only , the sum of the penalty points over all employees, is known. Kangho uses that: he splits the points among the employees however he likes, so that as many jobs as possible get done. The points given to one employee form a non-negative integer, and the points sum to exactly .
For example, employee 1 can do jobs 1, 2, 3, 4, 5, employees 2, 3, and 4 can do only job 1, and employee 5 can do jobs 1 and 5. With , giving 1 point to employee 1 and 1 point to employee 5 gets four jobs done. Giving both points to employee 1 instead lets employee 1 take three jobs, so employee 1 takes jobs 2, 3, 4, employee 2 takes job 1, and employee 5 takes job 5, which finishes all five.
Given the job list of every employee and the penalty sum , write a program that finds how many of the jobs can be done at most.
Input
The first line contains the number of employees , the number of jobs , and the penalty sum , separated by spaces. (, )
Each of the next lines describes one employee. Line contains the number of jobs employee can do, followed by those job numbers, separated by spaces. The count is between 0 and , and no number appears twice on the same line.
Output
Print the largest number of jobs Kangho's company can finish.