特殊约束背包AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)There are $N$ items $1, 2, \dots, N$.
Item $i$ has weight $w_i$ and value $v_i$.
For $i = 2, 3, \dots, N$, the following holds:
有 $N$ 个物品,编号为 $1, 2, \dots, N$。
物品 $i$ 的重量为 $w_i$,价值为 $v_i$。
对于 $i = 2, 3, \dots, N$,满足:AI (CI翻译)
$\sum_{j=1}^{i-1}{w_j} < w_i$
$\sum_{j=1}^{i-1}{w_j} < w_i$
Choose some (possibly zero) items such that the total weight is at most $W$.
Find the maximum possible total value of the chosen items.
Solve $T$ test cases per input.
选择若干个物品(可以一个也不选),使总重量不超过 $W$。
求所选物品的总价值的最大可能值。
每个输入包含 $T$ 组测试用例,请分别求解。AI (CI翻译)
Constraints
约束条件
AI (CI翻译)$1 \leq T \leq 2 \times 10^5$$1 \leq N \leq 60$$1 \leq w_i \leq W \leq 10^{18}$$\sum_{j=1}^{i-1}{w_j} < w_i \; (2 \leq i \leq N)$$1 \leq v_i \leq 10^{16}$- The sum of
$N$over all test cases is at most$2 \times 10^5$. - All input values are integers.
$1 \leq T \leq 2 \times 10^5$$1 \leq N \leq 60$$1 \leq w_i \leq W \leq 10^{18}$$\sum_{j=1}^{i-1}{w_j} < w_i \; (2 \leq i \leq N)$$1 \leq v_i \leq 10^{16}$- 所有测试用例的
$N$之和不超过$2 \times 10^5$。 - 所有输入值均为整数。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入从标准输入按以下格式给出:AI (CI翻译)
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_TAI (CI翻译)
Each test case $\mathrm{case}_t$ is given in the following format:
每组测试用例 $\mathrm{case}_t$ 按以下格式给出:AI (CI翻译)
N W
w_1 v_1
w_2 v_2
\vdots
w_N v_N
N W
w_1 v_1
w_2 v_2
\vdots
w_N v_NAI (CI翻译)
Output
输出格式
AI (CI翻译)Output the answers over a total of $T$ lines. The $t$-th line should contain the answer for the $t$-th test case.
共输出 $T$ 行答案。第 $t$ 行应包含第 $t$ 组测试用例的答案。AI (CI翻译)
样例
3
3 10
1 2
3 1
9 3
3 20
1 2
3 1
9 3
4 15
1 1
3 2
5 3
10 4
5
6
7
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。