AT_arc223_a.Unusual-Constraint Knapsack
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are N items 1,2,…,N.
Item i has weight wi and value vi.
For i=2,3,…,N, the following holds:
- ∑j=1i−1wj<wi
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.
共有 N 个物品,编号为 1,2,…,N。
物品 i 的重量为 wi,价值为 vi。
对 i=2,3,…,N,满足以下条件:
- ∑j=1i−1wj<wi
从中选择若干个(可能为零个)物品,使得所选物品的总重量不超过 W。
求所选物品的最大可能总价值。
每组输入包含 T 个测试用例。
输入格式
The input is given from Standard Input in the following format:
T
case1
case2
⋮
caseT
Each test case caset is given in the following format:
N W
w1 v1
w2 v2
⋮
wN vN
输入从标准输入中按以下格式给出:
T
case1
case2
⋮
caseT
每个测试用例 caset 按以下格式给出:
N W
w1 v1
w2 v2
⋮
wN vN
输出格式
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 个测试用例的答案。
输入输出样例
输入#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 1 and 3 gives a total weight of 10 and a total value of 5.
Moreover, it is impossible to achieve a total value of 6 or more while satisfying the condition.
Constraints
- 1≤T≤2×105
- 1≤N≤60
- 1≤wi≤W≤1018
- ∑j=1i−1wj<wi(2≤i≤N)
- 1≤vi≤1016
- The sum of N over all test cases is at most 2×105.
- All input values are integers.
样例 1 解释:
对于第一个测试用例,选择物品 1 和 3 可得到总重量为 10、总价值为 5。
此外,在满足约束条件的前提下,无法达到总价值 6 或更高。
约束条件
- 1≤T≤2×105
- 1≤N≤60
- 1≤wi≤W≤1018
- ∑j=1i−1wj<wi(2≤i≤N)
- 1≤vi≤1016
- 所有测试用例的 N 之和不超过 2×105。
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?