No.2741 Balanced Choice
Problem Statement
There are $N$ stones. The $i$-th stone has type $t_i$, weight $w_i$, and value $v_i$. Here, $t_i$ is either $0$ or $1$.
You choose some stones and put them in a box so that the total weight is at most $W$; however, the difference between the total weight of the stones of type $0$ and the total weight of the stones of type $1$ must be at most $D$.
Find the maximum possible total value when choosing stones so that these conditions are satisfied.
Constraints
- $1 \le N \le 5000$
- $1 \le W \le 5000$
- $1 \le D \le 5000$
- $1 \le w_i \le 5000$
- $1 \le v_i \le 5000$
- $t_i \in \{0,1\}$
- All input values are integers.
Input
The input is given from standard input in the following format.
$N$ $W$ $D$ $t_1$ $w_1$ $v_1$ $\vdots$ $t_N$ $w_N$ $v_N$
Output
Output the answer.
Sample
Sample 1
Input
5 10 2 0 3 1 0 3 2 1 4 3 1 2 4 1 5 5
Output
7
It is optimal to choose the $2,5$-th stones.
The total value is $2+5=7$, and the difference between the total weight $3$ of the stones of type $0$ and the total weight $5$ of the stones of type $1$ is $2$, which is at most $D$.
Sample 2
Input
5 100 1 1 3 1000 1 4 2000 1 2 3000 1 5 4000 1 8 5000
Output
0
No stone can be chosen.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。