No.2713 Just Solitaire
Problem Statement
Nafmo is playing a card game.
He currently has cards numbered from $1$ to $N$ in his hand. Using card number $i$ costs $A_i$ money.
There are also $M$ types of bonuses. The $i$-th bonus gives $B_i$ money when the following condition is achieved.
- For every integer $j$ satisfying $1 \leq j \leq K_i$, card number $C_{i,j}$ has been used.
Nafmo has a sufficiently large amount of money. Compute the maximum profit Nafmo can obtain by choosing the combination of cards to use optimally.
Here, the profit is defined as the money obtained from bonuses minus the money spent on using cards:
"$(ボーナスによって獲得できるお金) - (カードを使うために消費したお金)$"
The amount of money does not change except by using cards and obtaining bonuses.
Input
$N \ M$
$A_1 \ \dots \ A_N$
$B_1 \ \dots \ B_M$
$K_1 \ C_{1,1} \ \dots \ C_{1,K_1}$
$\ \vdots$
$K_M \ C_{M,1} \ \dots \ C_{M,K_M}$
- $1 \leq N, M \leq 100$
- $1 \leq A_i, B_i \leq 10^9$
- $1 \leq K_i \leq N$
- $1 \leq C_{i,1} < C_{i,2} < \dots < C_{i,K_i} \leq N$
- All inputs are integers.
Output
Output the maximum profit Nafmo can obtain.
Sample
Sample 1
Input
5 2 10 20 30 40 50 50 120 3 1 2 3 2 4 5
Output
30
The profit is maximized when cards $4, 5$ are used.
Money spent: $40+50 = 90$
Money obtained: $120$
Profit: $120 - 90 = 30$
Sample 2
Input
5 2 10 20 30 40 50 50 120 3 1 2 3 5 1 2 3 4 5
Output
20
The profit is maximized when all the cards are used.
Money spent: $10+20+30+40+50 = 150$
Money obtained: $50 + 120 = 170$
Profit: $170 - 150 = 20$
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
sepa38