Brewing potion 7 - MarisaOJ: Marisa Online Judge

Brewing potion 7

Time limit: 1000 ms
Memory limit: 256 MB
Marisa possesses $n$ bottles of potion, each containing a unique mixture. Among the available mushrooms, there are $a$ types categorized as "positive" and $b$ types categorized as "negative." Marisa's collection includes $A_i$ mushrooms of type $i$ that fall under the positive category, as well as $B_j$ mushrooms of type $j$ that belong to the negative category. Each bottle has specific restrictions on the types of mushrooms that can be added. To maintain stability, it is necessary to have an equal number of positive and negative mushrooms in each bottle. Your task is to determine the maximum number of mushrooms that Marisa can add to the $n$ bottles while adhering to these conditions. ### Input - The first line contains three integers $n,a,b$. - The second line contains $a$ integers $A_i$, the quantity of type $i$ positive. - The third line contains $b$ integers $B_j$, the quantity of type $j$ negative. - The following $3 \times n$ lines are grouped into sets of three lines each: + The first line of each group consists of three integers $C_i$, $P_i$, and $N_i$. Here, $C_i$ represents the capacity of potion bottle $i$ (i.e., the maximum number of mushrooms that can be added), $P_i$ represents the number of positive mushroom types it can contain, and $N_i$ represents the number of negative mushroom types it can contain. + The second line of each group contains $P_i$ integers, representing the types of positive mushrooms that bottle $i$ can contain. + The third line of each group contains $N_i$ integers, representing the types of negative mushrooms that bottle $i$ can contain. ### Output - Print the maximum number of mushrooms can be added to $n$ bottles. ### Constraints - $1 \le n, a, b \le 300$. - $1 \le A_i,B_i,C_i \le 10^6$. - $0 \le P_i\le a$. - $0 \le N_i \le b$ ### Example Input: ``` 2 3 2 1 1 1 1 1 3 1 1 1 1 5 2 1 2 3 2 ``` Output: ``` 4 ```