codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1446A.md (2211B)


      1 Source: https://codeforces.com/problemset/problem/1446/A
      2 
      3 A. Knapsack
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 You have a knapsack with the capacity of $W$. There are also $n$ items, the $i$-th one has weight $w_i$.
     22 
     23 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: $\lceil \frac{W}{2}\rceil \le C \le W$.
     24 
     25 Output the list of items you will put into the knapsack or determine that fulfilling the conditions is impossible.
     26 
     27 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.
     28 
     29 Input
     30 
     31 Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). Description of the test cases follows.
     32 
     33 The first line of each test case contains integers $n$ and $W$ ($1 \le n \le 200\,000$, $1\le W \le 10^{18}$).
     34 
     35 The second line of each test case contains $n$ integers $w_1, w_2, \dots, w_n$ ($1 \le w_i \le 10^9$) — weights of the items.
     36 
     37 The sum of $n$ over all test cases does not exceed $200\,000$.
     38 
     39 Output
     40 
     41 For each test case, if there is no solution, print a single integer $-1$.
     42 
     43 If there exists a solution consisting of $m$ items, print $m$ in the first line of the output and $m$ integers $j_1$, $j_2$, ..., $j_m$ ($1 \le j_i \le n$, all $j_i$ are distinct) in the second line of the output  — indices of the items you would like to pack into the knapsack.
     44 
     45 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.
     46 
     47 Example
     48 
     49 Input
     50 
     51 ```
     52 3
     53 1 3
     54 3
     55 6 2
     56 19 8 19 69 9 4
     57 7 12
     58 1 1 1 17 1 1 1
     59 ```
     60 
     61 Output
     62 
     63 ```
     64 1
     65 1
     66 -1
     67 6
     68 1 2 3 5 6 7
     69 ```
     70 
     71 Note
     72 
     73 In the first test case, you can take the item of weight $3$ and fill the knapsack just right.
     74 
     75 In the second test case, all the items are larger than the knapsack's capacity. Therefore, the answer is $-1$.
     76 
     77 In the third test case, you fill the knapsack exactly in half.