Ուղարկել | Բոլոր լուծումները | Լավագույն լուծումները | Վերադառնալ ցուցակին |
ACM_0074 - FAST FOOD PRIZES |
Around regional contest time, the Canadian branch of a popular fast food restaurant usually runs a game to promote its business. Certain food items provide stickers, and certain collection of dif- ferent stickers can be converted to cash prizes. If a prize requires sticker types T1, T2, . . . , Tk , then you can claim the prize if you have 1 sticker of each type T1, T2, . . . , Tk . Each sticker can only be used to claim one prize. However, you may claim a prize mul- tiple times if you have multiple stickers of the same type. No two prizes will require the same type of stickers. There may be some stickers that cannot be used to claim a cash prize (e.g. a sticker for a free milkshake).
On your road trip to the regional contest, your coach forced you to eat at this restaurant and collected all the stickers together. How much cash can your coach claim?
Input
The input consists of multiple test cases. The first line of input is a single integer, not more than 1000, indicating the number of test cases to follow. Each case starts with a line containing two integers n (1 ≤ n ≤ 10) and m (1 ≤ m ≤ 30), where n is the number of different types of prizes, and m is the number of different types of stickers (the types are labelled 1, 2, . . . , m). The next n lines specify the prizes. Each of these lines starts with an integer k (1 ≤ k ≤ m) specifying the number of sticker types required to claim the prize. This is followed by k integers specifying the types of the stickers required. The final integer on each line is the (positive) cash value of the prize (at most 1,000,000). The last line of each case gives m nonnegative integers, with the ith integer giving the number of stickers of type i your coach has collected. There are no more than 100 stickers of each type.
Output
For each case, display on a single line the total value of the cash prizes that can be claimed.
Examples
№ |
stdin |
stdout |
1 |
3 2 10 3 1 2 3 100 4 4 5 6 7 200 2 3 1 4 5 2 2 1 3 4 3 6 2 1 2 100 3 3 4 5 200 1 6 300 1 2 3 4 5 6 3 6 3 1 2 100 3 3 4 5 200 1 6 300 1 2 0 4 5 6 |
500 2500 1900 |
Ավելացրեց. | Հրանտ Հովհաննիսյան |
Ամսաթիվ. | 2014-01-07 |
Ժամանակի սահմանափակումը. | 1s |
Ծրագրի տեքստի սահմանափակումը. | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Լեզուներ. | Բոլորը բացի ASM32 ASM64 GAWK CLPS CLOJURE D ERL FSHARP FORTRAN GOSU HASK ICON ICK NEM NIM OBJC-CLANG PICO PIKE PYPY PYPY3 PY_NBC RUST SCM guile CHICKEN SED TCL WHITESPACE |
Աղբյուրը. | NA Rocky Mountain 2013.A |