AT_arc223_a.Unusual-Constraint Knapsack

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are NN items 1,2,…,N1, 2, \dots, N.
Item ii has weight wiw_i and value viv_i.
For i=2,3,…,Ni = 2, 3, \dots, N, the following holds:

  • ∑j=1i−1wj<wi\sum_{j=1}^{i-1}{w_j} < w_i

Choose some (possibly zero) items such that the total weight is at most WW.
Find the maximum possible total value of the chosen items.
Solve TT test cases per input.

共有 NN 个物品,编号为 1,2,…,N1, 2, \dots, N。
物品 ii 的重量为 wiw_i,价值为 viv_i。
对 i=2,3,…,Ni = 2, 3, \dots, N,满足以下条件:

  • ∑j=1i−1wj<wi\sum_{j=1}^{i-1}{w_j} < w_i

从中选择若干个(可能为零个)物品,使得所选物品的总重量不超过 WW。
求所选物品的最大可能总价值。
每组输入包含 TT 个测试用例。

输入格式

The input is given from Standard Input in the following format:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

Each test case caset\mathrm{case}_t is given in the following format:

NN WW
w1w_1 v1v_1
w2w_2 v2v_2
⋮\vdots
wNw_N vNv_N

输入从标准输入中按以下格式给出:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

每个测试用例 caset\mathrm{case}_t 按以下格式给出:

NN WW
w1w_1 v1v_1
w2w_2 v2v_2
⋮\vdots
wNw_N vNv_N

输出格式

Output the answers over a total of TT lines. The tt-th line should contain the answer for the tt-th test case.

在总共 TT 行上输出答案。第 tt 行应包含第 tt 个测试用例的答案。

输入输出样例

  • 输入#1

    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

    输出#1

    5
    6
    7

说明/提示

Sample 1 Explanation:
For the first test case, choosing items 11 and 33 gives a total weight of 1010 and a total value of 55.
Moreover, it is impossible to achieve a total value of 66 or more while satisfying the condition.

Constraints

  • 1≤T≤2×1051 \leq T \leq 2 \times 10^5
  • 1≤N≤601 \leq N \leq 60
  • 1≤wi≤W≤10181 \leq w_i \leq W \leq 10^{18}
  • ∑j=1i−1wj<wi  (2≤i≤N)\sum_{j=1}^{i-1}{w_j} < w_i \; (2 \leq i \leq N)
  • 1≤vi≤10161 \leq v_i \leq 10^{16}
  • The sum of NN over all test cases is at most 2×1052 \times 10^5.
  • All input values are integers.

样例 1 解释:
对于第一个测试用例,选择物品 11 和 33 可得到总重量为 1010、总价值为 55。
此外,在满足约束条件的前提下,无法达到总价值 66 或更高。

约束条件

  • 1≤T≤2×1051 \leq T \leq 2 \times 10^5
  • 1≤N≤601 \leq N \leq 60
  • 1≤wi≤W≤10181 \leq w_i \leq W \leq 10^{18}
  • ∑j=1i−1wj<wi  (2≤i≤N)\sum_{j=1}^{i-1}{w_j} < w_i \; (2 \leq i \leq N)
  • 1≤vi≤10161 \leq v_i \leq 10^{16}
  • 所有测试用例的 NN 之和不超过 2×1052 \times 10^5。
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页