Cramming Schedule
Time limit1sMemory limit1024 MB
Given exam deadlines, credits, and the study hours needed for each grade, find the highest credit-weighted grade point average when only one subject can be studied at a time.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Sorting, Greedy
- Solved
- No attempts yet
Problem
Yumin has to take final exams for subjects this semester. Each subject's grade is one of 13 levels, from lowest to highest: F, D-, D0, D+, C-, C0, C+, B-, B0, B+, A-, A0, A+. Their grade points are 0.0, 0.7, 1.0, 1.3, 1.7, 2.0, 2.3, 2.7, 3.0, 3.3, 3.7, 4.0, and 4.3, respectively.
The exam for subject is hours from now, and its credit count is . To earn the -th lowest grade in that subject, Yumin must study it for at least hours. Each subject can be studied only until its exam time, and Yumin cannot study two subjects at the same time. Taking an exam takes no time, and several exams can be taken at the same time.
Yumin has not studied at all yet and wants to maximize the grade point average through efficient cramming. The grade point average is the sum, over all subjects, of each subject's credits times the grade point earned in it, divided by the total credits of the subjects. A subject with an F still counts toward the total credits.
For example, in the situation above, the best strategy is as follows.
- Study Calculus 1 for 27 hours first.
- Next, study World History for 3 hours.
- Take the Calculus 1 exam. Having studied 27 hours in total, Yumin earns a B- (2.7).
- Study World History for 50 more hours.
- Take the World History exam. Having studied 53 hours in total, Yumin earns a B+ (3.3).
- Study Mathematics 3 for 100 hours.
- Take the Mathematics 3 exam. Having studied 100 hours in total, Yumin earns an A+ (4.3).
- Of the 20 hours left before the Information Science 3 exam, study Information Science 3 for at least 2 hours.
- Take the Information Science 3 exam. Having studied at least 2 hours in total, Yumin earns an A+ (4.3).
In this case, the grade point average is .
Input
The first line contains the number of subjects .
From the second line onward, the next lines describe the subjects. The -th line contains 15 integers , separated by spaces.
Output
Print the maximum grade point average Yumin can earn. An absolute or relative error of up to is allowed.