Majstor
InterviewTime limit3sMemory limit128 MB
Choose a prerequisite-closed set of jobs that maximizes total fee divided by total hours, with the quotient floored.
- Level
Medium7 of 10
- Topics
- Greedy, Sorting, Graph, Binary search
- Solved
- No attempts yet
Problem
Majstor Rajko has jobs to do. The jobs are not independent: every job has a list of jobs that must be finished before that job can be started. For every job Rajko also knows how many hours it takes him and how many kuna he is paid for finishing it.
Rajko is lazy, so he decided to do only some of the jobs, picking the set that gives him the highest possible hourly rate. After that he quits and leaves on holiday with the money he earned.
Rajko computes the hourly rate by dividing the total fee of the jobs he did by the total number of hours he spent, discarding the remainder. He does at least one job.
Consider these four jobs.
If Rajko does all four jobs, his hourly rate is kuna per hour. If he does only jobs 2 and 4, the rate is kuna per hour, and no choice that respects the prerequisites beats that. Jobs 2, 3 and 4 alone would give 268 kuna per hour, but job 3 cannot be done until job 1 is finished.
Write a program that determines the highest achievable hourly rate.
Input
The first line contains an integer (), the number of jobs.
Each of the next lines describes one job. The description of job starts with three integers , and (, , ): the fee in kuna for finishing the job, the number of hours the job takes, and the number of jobs that must be finished before job . Then integers follow, the numbers of those jobs.
The prerequisites are always such that there is a way to finish every job.
Output
Print the highest achievable hourly rate in kuna on a single line. The rate is the total fee divided by the total hours with the remainder discarded, so the answer is an integer.