問題一覧 > 通常問題

No.2713 Just Solitaire

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 84
作問者 : Nafmo2 / テスター : dyktr_06 sepa38
お気に入りにしたユーザー ProblemId : 10584 / 自分の提出
問題文最終更新日: 2024-03-29 00:46:18
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 425 (MMA Contest 018) (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。