Course Load
Time limit1sMemory limit128 MB
Pick a set of classes with pairwise disjoint meeting slots and total workload at most C, maximizing total utility.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Bit manipulation, Brute force
- Solved
- No attempts yet
Problem
A university offers a large number of fantastic courses you might want to take: classes on algorithms, stage make-up, the universe, yoga, leadership, and many more. Whenever you try to decide which classes to take, you always run into two problems:
- The most exciting classes always overlap with one another.
- There are only so many hours in the day to work and study.
To be systematic about it, model this as an optimization problem. For each class you assign a utility : the benefit you would derive from taking it (fun, job skills, or whatever else). Each class also has a workload : the units of work per week required to pass. (The workload need not correlate with how often the class meets per week.) Finally, each class occupies a fixed set of meeting slots during the week.
Select a set of classes that do not overlap in their meeting times and whose total workload does not exceed your work capacity , so as to maximize your total utility.
Input
The first line contains a number , the number of data sets in the input. It is followed by data sets, each of the following form.
The first line of a data set contains three integers , , and :
- is the number of classes you are considering.
- is the number of class meeting slots in the week (a meeting slot could be, for instance, "Monday 3:30-4:50").
- is your capacity for class work.
This is followed by lines, each describing one class. For class , the line contains the integer utility , then the workload , then the number of meetings , followed by integers between and giving the meeting slots the class occupies.
Output
For each data set, first output a line "Data Set x:" by itself, where is the data set's number (starting from ). Then, on the next line, output the maximum total utility achievable by any set of non-overlapping classes whose total workload is at most . (You do not need to output which classes achieve this utility.)