#P1361. 小M的作物
小M的作物
Description
Xiao M opened two huge farmlands and in MC (you can assume their capacity is infinite). Now, Xiao P has seeds of crop types, exactly seed for each type (i.e., you can plant at most one plant of each type), numbered from to .
For the -th crop, planting it in yields a profit of , and planting it in yields a profit of . There is also a special phenomenon: certain sets of crops planted together on the same field yield an extra profit. Xiao M found such crop combinations in total. For the -th combination, if all its crops are planted together in , you gain an extra profit; if they are planted together in , you gain an extra profit.
Xiao M quickly computed the maximum profit, but he wants to test you. Can you answer this question?
Input Format
The first line contains an integer , the number of crop types.
The second line contains integers, representing .
The third line contains integers, representing .
The fourth line contains an integer , the number of combinations.
Each of the next lines describes one combination: on the -th line, the first integer is the number of crops in the -th combination, followed by two integers , then integers indicating the indices of the crops in this combination.
Output Format
Output a single line containing one integer, the maximum profit.
3
4 2 1
2 3 2
1
2 3 2 1 2
11
Hint
Sample Explanation:
Plant crops in field , and crop in field . Profit: .
Constraints:
For of the testdata, , . All values that appear in the problem are non-negative integers not exceeding .
Translated by ChatGPT 5
京公网安备 11011102002149号