No.2701 A cans -> B cans
タグ : / 解いたユーザー数 65
作問者 :
Magentor
/ テスター :
👑
hamamu
Problem Statement
Solve the following problem independently for each of $p=1,2,\dots,M$.
Magentor has $p$ empty cans $0$.
There are also $N$ shops. At the $i$-th shop, he can hand over a total of $A_i$ cans, each of which is an empty can $0$ or an empty can $i$, and receive $B_i$ juice-filled cans $i$ in exchange. Here, $A_i>B_i$ is guaranteed.
By drinking the juice, Magentor can turn $1$ juice-filled can $i$ into $1$ empty can $i$. When he does so, he gains $C_i$ happiness.
Find the maximum total happiness Magentor can obtain.
Input
$N\ M$ $A_1\ B_1\ C_1$ $A_2\ B_2\ C_2$ $\vdots$ $A_N\ B_N\ C_N$
- $1\leq N\leq 5000$
- $2\leq M\leq 5000$
- $1\leq B_i<A_i\leq M$
- $1\leq C_i\leq 10^9$
- All input values are integers.
Output
Output $M$ lines.
On the $i$-th line, output the answer for $p=i$.
Sample
Sample 1
Input
2 5 4 3 3 5 2 8
Output
0 0 0 9 18
When $p=5$, Magentor initially has $5$ empty cans $0$. He can make the total happiness $18$ as follows.
- At shop $1$, exchange $4$ empty cans $0$ for $3$ juice-filled cans $1$.
- Turn the $3$ juice-filled cans $1$ into $3$ empty cans $1$. He gains $9$ happiness.
- At shop $1$, exchange $1$ empty can $0$ and $3$ empty cans $1$ for $3$ juice-filled cans $1$.
- Turn the $3$ juice-filled cans $1$ into $3$ empty cans $1$. He gains $9$ happiness.
The total happiness cannot be made $19$ or more no matter what he does, so the answer for $p=5$ is $18$.
Sample 2
Input
1 2 2 1 1000000000
Output
0 1000000000
Sample 3
Input
3 10 9 8 1 5 1 8 5 2 4
Output
0 0 0 0 8 8 8 16 16 16
Note that empty cans $1$ cannot be exchanged at shop $2$ or shop $3$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。