1791G1.md (2540B)
1 Source: https://codeforces.com/problemset/problem/1791/G1 2 3 G1. Teleporters (Easy Version) 4 5 time limit per test 6 7 1 second 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 The only difference between the easy and hard versions are the locations you can teleport to. 22 23 Consider the points $0, 1, \dots, n$ on the number line. There is a teleporter located on each of the points $1, 2, \dots, n$. At point $i$, you can do the following: 24 25 * Move left one unit: it costs $1$ coin. 26 * Move right one unit: it costs $1$ coin. 27 * Use a teleporter at point $i$, if it exists: it costs $a_i$ coins. As a result, you teleport to point $0$. Once you use a teleporter, you can't use it again. 28 29 You have $c$ coins, and you start at point $0$. What's the most number of teleporters you can use? 30 31 Input 32 33 The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) — the number of test cases. The descriptions of the test cases follow. 34 35 The first line of each test case contains two integers $n$ and $c$ ($1 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^9$) — the length of the array and the number of coins you have respectively. 36 37 The following line contains $n$ space-separated integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) — the costs to use the teleporters. 38 39 It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot10^5$. 40 41 Output 42 43 For each test case, output the maximum number of teleporters you can use. 44 45 Example 46 47 Input 48 49 ``` 50 10 51 52 5 6 53 54 1 1 1 1 1 55 56 8 32 57 58 100 52 13 6 9 4 100 35 59 60 1 1 61 62 5 63 64 4 5 65 66 4 3 2 1 67 68 5 9 69 70 2 3 1 4 1 71 72 5 8 73 74 2 3 1 4 1 75 76 4 3 77 78 2 3 4 1 79 80 4 9 81 82 5 4 3 3 83 84 2 14 85 86 7 5 87 88 5 600000000 89 90 500000000 400000000 300000000 200000000 100000000 91 ``` 92 93 Output 94 95 ``` 96 2 97 2 98 0 99 1 100 2 101 2 102 1 103 1 104 1 105 2 106 ``` 107 108 Note 109 110 In the first test case, you can move one unit to the right, use the teleporter at index $1$ and teleport to point $0$, move two units to the right and use the teleporter at index $2$. You are left with $6-1-1-2-1 = 1$ coins you don't have enough coins to use another teleporter. You have used two teleporters, so the answer is two. 111 112 In the second test case, you go four units to the right and use the teleporter to go to $0$, then go six units right and use the teleporter at index $6$ to go to $0$. The total cost will be $4+6+6+4 = 20$. You are left with $12$ coins, but it is not enough to reach any other teleporter and use it so the answer is $2$. 113 114 In the third test case, you don't have enough coins to use any teleporter, so the answer is zero.