問題一覧 > 通常問題

No.2741 Balanced Choice

レベル : / AI推定難易度 : 1150 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 84
作問者 : Nzt3 / テスター : kenken714 ponjuice cho435
お気に入りにしたユーザー ProblemId : 10837 / 自分の提出
問題文最終更新日: 2024-04-26 13:00:57
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
CPCTF 2024 : PPC (順位表) の他の問題:

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