ZOJ Problem Set - 1980
A technique used in early programming contest strategies involved partitioning the available intellectual capacity of a team into a number of members with each member having a fixed amount of intelligence, different members potentially having different amounts. The sum of the brightness of all members equals the total intellectual capacity of the team.
Given a set of problems, it was the task of the team to assign the problems to different team members, so that they could be solved concurrently. This was made difficult due to the fact that the solution time of a problem might depend on the amount of intelligence available to it. Every problem has a minimum intelligence requirement, but if assigned to a brighter member its solution time might increase or decrease.
In this task, you have to determine optimal assignments of problems to team members. Your program is given the intellectual capacities of the team members available for the solution of problems, and for each problem a description of how its solution time depends on the amount of intelligence available to it. Your program has to find the solution schedule of the problems that minimizes the average solution time for the problems. A solution schedule is an assignment of problems to team members and times, such that no two problems use the same member at the same time, and no problem is assigned to a team member with less brightness than its minimum requirement. The solution time of the problem is the difference between the time when the problem was submitted to be solved (which is the start of the contest at time zero for all problems in this task), and the time that the problem is solved.
The input data will contain multiple test cases. Each test case begins with a line containing a pair of integers m and n. The number m specifies the number of team members (1 <= m <= 3), and n specifies the number of problems to be solved (1 <= n <= 10).
The next line contains m positive integers giving the intelligence amounts of the m team members. Following this are n lines, describing the time-brightness tradeoffs for each of the n problems. Each line starts with a positive integer k (k <= 10), followed by k pairs of positive integers s1,t1,s2,t2,...,sk,tk that satisfy si < si+1 for 1 <= i < k. The minimum intelligence requirement of the problem is s1, i.e. it cannot be solved by a member with less intellectual capacity than this number. If the problem is solved by a team member with brightness s, where si <= s < si+1 for some i, then its solution time will be ti. Finally, if the problem is solved by a team member with intellectual capacity sk or more, then its execution time will be tk.
A pair of zeroes will follow the input for the last test case.
You may assume that each problem will be solved in exactly the time specified for the given brightness, regardless of the number of other problems being solved by other team members at the same time. No problem will have an intelligence requirement larger than that of the brightest team member.
For each test case, first display the case number (starting with 1 and increasing sequentially). Then print the minimum average solution time for the set of problems with two digits to the right of the decimal point. Follow this by the description of a solution schedule that achieves this average solution time. Display one line for each problem, in the order they were given in the input, that identifies the problem number, the member used to solve it (numbered in the order given in the input), the time when the member started to solve the problem, and the time when the problem was solved. Follow the format shown in the sample output, and print a blank line after each test case.
Source: University of Ulm Local Contest 2003