A thief is trying to steal some items from a rich palace. The thief wants to maximize what he takes out, but he only has a limited amount of space to carry things with. your mission is to help him maximize the amount he takes out.
the first couple of lines will describe the items he can
take. Each line is of the form:
For each test case, you have to print the maximum value the thief can take out, and what items to grab. The format should be:
where max is the max value the thief can get, and item,item,... are the names of the items to be taken. The list should be sorted alphabetically. The last item should not be followed by a comma. If no items can be taken, then just print a 0 and list no items. For obvious reasons, no item can be included more than once.
15 10
3 30
5 4
100 3
90 100
5 3
5 6
5 9
$END
2
50
300
0
135 A,C,D,F,G,H
228 A,B,C,D,E,F,G,H