Optimal Strategy for the ICPC

Time limit1sMemory limit128 MB

Summary
Given up to 15 problem solving times, schedule them on three parallel workers within 300 minutes to maximize solved count, then minimize total completion-time penalty, with lexicographically smallest order.
Level

Hard8 of 10

Topics
Dynamic programming, Bit manipulation, Sorting, Greedy
Solved
No attempts yet

Problem

A three-member team competes in an ICPC-style programming contest. The contest lasts exactly 300 minutes.

The team's score is the sum, over every solved problem, of the time consumed for that problem. The time consumed for a solved problem is the number of minutes from the start of the contest to the submission of its first accepted run, plus 20 penalty minutes for each previously rejected run of that problem. A problem that is not solved contributes nothing.

One element of the optimal strategy is simply to make no incorrect submissions, so the team never has to worry about penalty minutes. All that remains is to decide the order in which the problems are submitted.

Assume the team can estimate the development time required for each problem exactly. The three members each think about a different problem rather than all working on the same one, each member types infinitely fast, and no member uses a terminal while thinking. Hence up to three problems can be in progress at the same time, and all three members may even submit a problem within the same minute.

A problem counts as solved only if it is submitted within the 300 minutes of the contest. Determine a strategy that solves the greatest number of problems and, among those, achieves the best (smallest) possible score. If several strategies solve the same number of problems with the same score, report the submission order that comes first lexicographically.

Input

The first line contains a single integer nn (0<n<1000 < n < 100), the number of data sets — one per set of problems. Each of the following nn lines describes one data set. The line begins with an integer kk (5≤k≤155 \le k \le 15), the number of problems in that data set, followed by kk integers between 11 and 300300 inclusive, giving the estimated time required to solve each problem. The problems are labeled with the uppercase letters A,B,C,…A, B, C, \ldots in the order given. The contest lasts exactly 300300 minutes.

Output

For each data set, print one line containing, in order: the text Data set X: (where XX is the data set number starting from 11), the labels of the solved problems in the order they are submitted, the total number of problems solved, and the final penalty score. All entries on a line are separated by single spaces.

Examples2

  1. Example 1

    Input
    4
    9 25 50 100 150 100 100 150 225 300
    10 60 120 99 129 15 150 225 135 50 123
    12 6 60 99 45 135 66 231 63 96 39 50 123
    15 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75
    
    Expected output
    Data set 1: A B C D E F G H 8 1450
    Data set 2: E I A J C B F H D 9 1473
    Data set 3: A J D B K F H I C E L 11 1452
    Data set 4: A B C D E F G H I J K L 12 2250
    
  2. Example 2

    Input
    1
    5 10 20 30 40 50
    
    Expected output
    Data set 1: A B C D E 5 180