407516: GYM102821 H Hack a Contest
Description
Fish just participated in a programming contest. Before the final standing being public, he hacks the database and wants to change his result!
The database he accessed records the number of times he submitted for each problem and the result (AC or not) for each submission. Soon he finds out that even thought the time for each submission is stored in random order, he can not change it at all (neither the number of submissions for each problem). What he can modify is problem id and result for each submission. In order not to make things too strange, there should not be any submissions for a problem after he has already got an AC in this problem in the end.
You must have known that participants are ranked according to the most problems solved and then ranked by least penalty for those in the same place. The penalty is the sum of the time consumed for each problem solved. The time consumed for a solved problem is the time for its first AC submission, plus $$$20$$$ for every previously not AC submissions for that problem.
Please help Fish find the best result he can get.
InputThe first line of input contains an integer $$$T$$$, representing the number of test cases.
Then for each test case:
The first line contains two integers $$$N, M$$$, the number of submissions and number of problems.
The second line contains $$$N$$$ integers $$$t_i$$$, the time of each submission.
The third line contains $$$M$$$ integers $$$c_i$$$, the number of submissions on each problem.
OutputFor each test cases, you should output Case $$$x$$$: $$$y$$$, where $$$x$$$ indicates the case number starting from $$$1$$$, and $$$y$$$ is the penalty for his best result.
ExampleInput2 4 2 10 20 30 40 2 2 4 3 10 20 30 40 1 1 2Output
Case 1: 100 Case 2: 90Note
$$$1 \le T \le 100$$$
$$$1 \le N \le 10^5$$$
$$$1 \le M \le min(N, 13)$$$
$$$1 \le t_i \le 300$$$
$$$\sum c_i = N$$$
For $$$90\%$$$ test cases: $$$N \le 100$$$