Fixed Partition Contest Management
Time limit1sMemory limit128 MB
Assign up to 10 problems to at most 3 members and order each member's load to minimize the sum of completion times, where a problem's duration depends on the solver's brightness.
- Level
Medium6 of 10
- Topics
- Brute force, Dynamic programming, Greedy, Sorting
- Solved
- No attempts yet
Problem
A team's total intellectual capacity is split among several members. Each member has a fixed amount of intelligence (its “brightness”), and different members may have different amounts; the sum of all members' brightness is the team's total intellectual capacity.
You are given a set of problems, and the team must assign each problem to a member so that they can be solved concurrently. No member may work on two problems at the same time, and a problem may only be given to a member whose brightness is at least the problem's minimum requirement. The time needed to solve a problem depends on the brightness of the member who solves it: giving it to a brighter member may make the solution time shorter, or longer.
Every problem is submitted at the start of the contest, time . The solution time of a problem is the moment at which it is solved (equal to its completion time, since it is submitted at time ).
Choose which member solves each problem, and the order in which each member solves its assigned problems (so that no member solves two problems at once), to minimize the sum of the solution times of all problems.
Input
The input contains several test cases. Each test case begins with a line containing two integers and , where is the number of team members () and is the number of problems to solve ().
The next line contains positive integers giving the brightness of each member, in order.
The following lines describe the time–brightness tradeoff of each problem. Each line starts with a positive integer (), followed by pairs of positive integers satisfying for . The problem's minimum brightness requirement is ; a member with less brightness cannot solve it. If a member with brightness solves the problem and for some , the solution time is ; if the member's brightness is at least , the solution time is .
The line follows the last test case and marks the end of the input.
Each problem takes exactly the time specified for the given brightness, no matter how many other problems other members are solving at the same time. No problem has a brightness requirement larger than the brightest member's brightness.
Output
For each test case, print one line in the form Case X: T, where is the test case number (starting at and increasing by ) and is the minimum achievable sum of the solution times of all problems — that is, over all valid assignments and orderings, the smallest possible total of the problems' solution times, printed as an integer.