
"Shut the Box" is a single-player game that begins with a set of pieces numbered from to . All pieces are initially unmarked (in the picture, unmarked pieces are in the upright position). In this version of the game, a player is allowed up to turns, each defined by an independently chosen value (typically determined by rolling one or more dice). During a turn, the player must select a set of currently unmarked pieces whose numeric labels sum exactly to , and then mark them. The game continues either until the player has used all turns, or until a turn occurs in which it is impossible to select a set of unmarked pieces summing to the given value (in which case that turn and all remaining turns are forfeited). The goal is to mark as many pieces as possible; marking all pieces is called shutting the box. Your task is to determine the maximum number of pieces that can be marked using a fixed sequence of turn values.
As an example, consider a game with pieces and the following sequence of turn values: 10,\ 3,\ 4,\ 2. The best result for this sequence is to mark a total of four pieces. This can be achieved by using the value to mark the pieces 1 + 4 + 5, then using the value to mark piece . At this point the game ends, as it is impossible to exactly use the turn with value (the final turn with value must also be forfeited). An alternative strategy to achieve the same count is to use to mark four pieces 1 + 2 + 3 + 4, with the game ending on the turn with value . There is no way to mark five or more pieces with that sequence.
Hint: Avoid enormous arrays or lists, if possible.
Each game begins with a line containing two integers and , where 1 \leq N \leq 22 is the number of pieces and 1 \leq T \leq N is the maximum allowed number of turns. The next line contains integers designating the sequence of turn values ; each such value satisfies 1 \leq V \leq 22. You must read this entire sequence from input, even if a particular game ends on an unsuccessful turn before the end of the sequence. The data set ends with a line containing .
For each game, output a line as shown below, reporting the game's serial number and the maximum number of pieces that can be marked during that game.
Beispiel 1