Professor Spook is consulting for NASA, which is planning ~a~ series of space shuttle flights and must decide which commercial experiments to perform and which instruments to have on board each flight. For each flight NASA considers ~a~ set ~E =~ ~\{ E_1, E_2, \dots, E_m \}~ of instruments experiments and the commercial sponsor of ~E_j~ has agreed to pay NASA ~p_j~ dollars for the results of the experiments.
The experiments use a set ~I =~ ~\{ I_1, I_2, \dots, I_n \}~ of instruments; each experiment ~E_j~ requires some of the instruments from the set. The cost of carrying instruments ~I_k~ is ~c_k~ dollars. And an instrument can be used for multiple experiments.
The professor's job is to determine which experiments to perform and which instruments to carry for a given flight in order to maximize the net revenue, which is the total income from the experiments performed minus the total cost of the instruments carried. Since he is not a programmer, he asked your help.
Input
- Input starts with an integer ~T~ ~(\leq 100)~, denoting the number of test cases.
- Each case starts with a line containing two integers ~m~ ~(1 \leq m \leq 1000)~ and ~n~ ~(1 \leq n \leq 1000)~, where ~m~ denotes the number of experiments and ~n~ denotes the number of instruments. The next line contains ~m~ space separated integers, where the ~j_{th}~ integer denotes the commercial sponsor of ~E_j~ paying NASA ~p_j~ ~(1 \leq~ ~p_j~ ~\leq 10000)~ dollars for the result of the experiment. The next line contains ~n~ space separated integers, where the ~k_{th}~ integer denotes the cost of carrying the ~k_{th}~ instrument, ~c_k~ ~(1 \leq~ ~c_k~ ~\leq 10000)~. Each of the next ~m~ lines contains an integer ~q_i~ ~(1 \leq~ ~q_i~ ~\leq n)~ followed by ~q_i~ distinct integers each between ~1~ and ~n~, separated by spaces. These ~q_i~ integers denote the required instruments for the ~i_{th}~ experiment.
Output
- For each case, print the case number and the maximum revenue NASA can make using the experiments.
Sample Input
2
1 1
10
20
1 1
3 5
20 30 40
1 2 30 4 50
3 1 2 3
3 2 3 4
1 5
Sample Output
Case 1: 0
Case 2: 13
Bình luận