問題一覧 > 通常問題

No.1678 Coin Trade (Multiple)

レベル : / AI推定難易度 : 2300 / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 41
作問者 : stoq / テスター : akakimidori chocorusk
お気に入りにしたユーザー ProblemId : 6813 / 自分の提出
問題文最終更新日: 2021-09-10 21:32:25
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 313 (順位表) の他の問題:

Preface

The following two problems, including this one, differ only in their constraints and time limits.

Coin Trade (Single)
Coin Trade (Multiple)

Problem Statement

yuki is planning a trip visiting country $1,$ country $2,\dots,$ country $N$ in this order.

The coin used in country $i$ is worth $A_i$ yen each. In addition, some countries have people interested in foreign coins, and you can exchange coins obtained in another country for coins of the country you are currently in.

In country $i$, you may choose zero or more of the following actions and perform them in any order.

  • Choose $j > 0$. Pay $A_i \times j$ yen and obtain $j$ coins of country $i$.
  • If you hold any of the $M_i$ kinds of coins of countries $B_{i1},B_{i2},\dots,B_{iM_i} \ (< i)$, you can exchange one such coin for one coin of country $i$.
    You may exchange multiple kinds of coins at the same time, but you cannot exchange two or more coins of the same kind for coins of country $i$. (Text corrected at 21:32)

However, since your wallet has limited capacity, you are not allowed to obtain coins in a way that would make the number of coins you hold exceed $K$ (yen is not counted).

Immediately after finishing the above actions each time, you may convert zero or more of the coins you hold into yen. A coin worth $A_i$ yen is converted into $A_i$ yen.

If you act optimally, how much can your yen increase between before the start of the trip and after the end of the trip? Find the maximum value.

You may assume that you have enough yen that it never runs out during the trip.

Input

$N\ K$
$A_1\ M_1$
$B_{11}\ B_{12} \dots B_{1M_1}$
$A_2\ M_2$
$B_{21}\ B_{22} \dots B_{2M_2}$
$\vdots$
$A_N\ M_N$
$B_{N1}\ B_{N2} \dots B_{NM_N}$

  • All inputs are integers
  • $1 \leq N \leq 5 \times 10^4$
  • $1 \leq K \leq 50$
  • $1 \leq A_i \leq 10^9$
  • $0 \leq M_i < i$
  • $\sum_{i=1}^{N} M_i \leq 5 \times 10^4$
  • $1 \leq B_{i1} < B_{i2} < \dots < B_{iM_i} < i \ (1 \leq i \leq N)$

Output

Output the maximum value of the difference in yen between before the end of the trip and after the end of the trip when acting optimally.

Sample

Sample 1
Input
2 1
3 0

5 1
1
Output
2

Spend $3$ yen in country $1$ to obtain a coin of country $1$, then exchange it for a coin of country $2$ and convert it, which gives you $5$ yen.
You gain $2$ yen in total, so output 2.

Sample 2
Input
3 2
1 0

2 1
1
3 1
1
Output
3

It is optimal to pay $2$ yen in country $1$ to obtain $2$ coins, exchange them in countries $2,3$, and then convert them.

Sample 3
Input
15 3
2 0

1 0

14 1
2
20 1
1
11 1
3
1 0

10 0

7 1
1
17 1
6
4 1
6
11 0

20 5
3 5 6 10 11
4 2
6 11
1 1
13
7 3
4 8 11
Output
96

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。