CF1446A.Knapsack

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You have a knapsack with the capacity of WW. There are also nn items, the ii-th one has weight wiw_i.

You want to put some of these items into the knapsack in such a way that their total weight CC is at least half of its size, but (obviously) does not exceed it. Formally, CC should satisfy: ⌈W2⌉≤C≤W\lceil \frac{W}{2}\rceil \le C \le W.

Output the list of items you will put into the knapsack or determine that fulfilling the conditions is impossible.

If there are several possible lists of items satisfying the conditions, you can output any. Note that you don't have to maximize the sum of weights of items in the knapsack.

你有一个容量为 WW 的背包。此外还有 nn 个物品,其中第 ii 个物品的重量为 wiw_i。

你需要从中选择若干物品放入背包,使得它们的总重量 CC 至少为背包容量的一半(向上取整),但又不超过背包容量。形式化地,CC 应满足:⌈W2⌉≤C≤W\lceil \frac{W}{2}\rceil \le C \le W。

请输出将要放入背包的物品列表;若无法满足条件,则输出说明该情况不可能。

若存在多种满足条件的物品列表,输出任意一种即可。注意:你不必最大化背包中物品的总重量。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). Description of the test cases follows.

The first line of each test case contains integers nn and WW (1≤n≤200 0001 \le n \le 200\,000, 1≤W≤10181\le W \le 10^{18}).

The second line of each test case contains nn integers w1,w2,…,wnw_1, w_2, \dots, w_n (1≤wi≤1091 \le w_i \le 10^9) — weights of the items.

The sum of nn over all test cases does not exceed 200 000200\,000.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 WW(1≤n≤200 0001 \le n \le 200\,000,1≤W≤10181\le W \le 10^{18})。

每个测试用例的第二行包含 nn 个整数 w1,w2,…,wnw_1, w_2, \dots, w_n(1≤wi≤1091 \le w_i \le 10^9)—— 各物品的重量。

所有测试用例的 nn 值之和不超过 200 000200\,000。

输出格式

For each test case, if there is no solution, print a single integer −1-1.

If there exists a solution consisting of mm items, print mm in the first line of the output and mm integers j1j_1, j2j_2, ..., jmj_m (1≤ji≤n1 \le j_i \le n, all jij_i are distinct) in the second line of the output — indices of the items you would like to pack into the knapsack.

If there are several possible lists of items satisfying the conditions, you can output any. Note that you don't have to maximize the sum of weights items in the knapsack.

对于每个测试用例,若无解,则输出单个整数 −1-1。

若存在一个由 mm 个物品组成的解,则在输出的第一行打印 mm,在第二行打印 mm 个整数 j1j_1, j2j_2, ..., jmj_m(其中 1≤ji≤n1 \le j_i \le n,且所有 jij_i 互不相同)——即你希望装入背包的物品的索引。

若存在多个满足条件的物品列表,你可以输出任意一个。注意:你无需最大化背包中物品的总重量。

输入输出样例

  • 输入#1

    3
    1 3
    3
    6 2
    19 8 19 69 9 4
    7 12
    1 1 1 17 1 1 1

    输出#1

    1
    1
    -1
    6
    1 2 3 5 6 7

说明/提示

In the first test case, you can take the item of weight 33 and fill the knapsack just right.

In the second test case, all the items are larger than the knapsack's capacity. Therefore, the answer is −1-1.

In the third test case, you fill the knapsack exactly in half.

在第一个测试用例中,你可以选择重量为 33 的物品,恰好将背包装满。

在第二个测试用例中,所有物品的重量均大于背包的容量,因此答案为 −1-1。

在第三个测试用例中,你恰好将背包装满一半。

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

首页