CF1446A.Knapsack
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have a knapsack with the capacity of W . There are also n items, the i -th one has weight wi .
You want to put some of these items into the knapsack in such a way that their total weight C is at least half of its size, but (obviously) does not exceed it. Formally, C should satisfy: ⌈2W⌉≤C≤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.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t ( 1≤t≤104 ). Description of the test cases follows.
The first line of each test case contains integers n and W ( 1≤n≤200000 , 1≤W≤1018 ).
The second line of each test case contains n integers w1,w2,…,wn ( 1≤wi≤109 ) — weights of the items.
The sum of n over all test cases does not exceed 200000 .
输出格式
For each test case, if there is no solution, print a single integer −1 .
If there exists a solution consisting of m items, print m in the first line of the output and m integers j1 , j2 , ..., jm ( 1≤ji≤n , all ji 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
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 3 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 .
In the third test case, you fill the knapsack exactly in half.