310165: CF1791G1. Teleporters (Easy Version)

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Teleporters (Easy Version)

题意翻译

有 $t$ 组数据,每次给出 $n$、$c$ 和 $n$ 个整数 $a_i$。 你现在在 $0$ 点,在 $1 \sim n$ 中每个点上都有一个传送器,**且每个传送器只能使用一次**,在点 $i$,可以执行如下操作: * 向左移动一个单位,花费 $1$ 硬币。 * 向右移动一个单位,花费 $1$ 硬币。 * 在点 $i$ 使用传送器,传送回到 $0$ 点,花费 $a_i$ 个硬币。 你有 $c$ 个硬币,求出从 $0$ 点出发,最多可以使用的传送器个数。

题目描述

The only difference between the easy and hard versions are the locations you can teleport to. 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: - Move left one unit: it costs $ 1 $ coin. - Move right one unit: it costs $ 1 $ coin. - 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. You have $ c $ coins, and you start at point $ 0 $ . What's the most number of teleporters you can use?

输入输出格式

输入格式


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. 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. 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. It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 2\cdot10^5 $ .

输出格式


For each test case, output the maximum number of teleporters you can use.

输入输出样例

输入样例 #1

10
5 6
1 1 1 1 1
8 32
100 52 13 6 9 4 100 35
1 1
5
4 5
4 3 2 1
5 9
2 3 1 4 1
5 8
2 3 1 4 1
4 3
2 3 4 1
4 9
5 4 3 3
2 14
7 5
5 600000000
500000000 400000000 300000000 200000000 100000000

输出样例 #1

2
2
0
1
2
2
1
1
1
2

说明

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. 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 $ . In the third test case, you don't have enough coins to use any teleporter, so the answer is zero.

Input

题意翻译

有 $t$ 组数据,每次给出 $n$、$c$ 和 $n$ 个整数 $a_i$。 你现在在 $0$ 点,在 $1 \sim n$ 中每个点上都有一个传送器,**且每个传送器只能使用一次**,在点 $i$,可以执行如下操作: * 向左移动一个单位,花费 $1$ 硬币。 * 向右移动一个单位,花费 $1$ 硬币。 * 在点 $i$ 使用传送器,传送回到 $0$ 点,花费 $a_i$ 个硬币。 你有 $c$ 个硬币,求出从 $0$ 点出发,最多可以使用的传送器个数。

Output

**题目大意**:

题目描述了一个在数轴上的游戏,数轴上有0到n的点,每个点i(1到n)上都有一个传送器。你可以从点0开始,执行以下操作:

- 向左或向右移动一个单位,每次移动花费1枚硬币。
- 使用点i上的传送器回到点0,使用传送器需要花费a_i枚硬币。一旦使用了传送器,就不能再次使用。

你总共有c枚硬币,需要计算从点0出发,最多可以使用多少次传送器。

**输入输出数据格式**:

**输入格式**:

第一行包含一个整数t(1≤t≤1000),表示测试用例的数量。

每个测试用例包含两行:

- 第一行包含两个整数n和c(1≤n≤2×10^5;1≤c≤10^9),分别表示传送器的数量和你的硬币数。
- 第二行包含n个整数a_1, a_2, ..., a_n(1≤a_i≤10^9),表示使用每个传送器需要花费的硬币数。

保证所有测试用例的n之和不超过2×10^5。

**输出格式**:

对于每个测试用例,输出一行,表示最多可以使用的传送器数量。

**输入输出样例**:

**输入样例 #1**:

```
10
5 6
1 1 1 1 1
8 32
100 52 13 6 9 4 100 35
1 1
5
4 5
4 3 2 1
5 9
2 3 1 4 1
5 8
2 3 1 4 1
4 3
2 3 4 1
4 9
5 4 3 3
2 14
7 5
5 600000000
500000000 400000000 300000000 200000000 100000000
```

**输出样例 #1**:

```
2
2
0
1
2
2
1
1
1
2
```**题目大意**: 题目描述了一个在数轴上的游戏,数轴上有0到n的点,每个点i(1到n)上都有一个传送器。你可以从点0开始,执行以下操作: - 向左或向右移动一个单位,每次移动花费1枚硬币。 - 使用点i上的传送器回到点0,使用传送器需要花费a_i枚硬币。一旦使用了传送器,就不能再次使用。 你总共有c枚硬币,需要计算从点0出发,最多可以使用多少次传送器。 **输入输出数据格式**: **输入格式**: 第一行包含一个整数t(1≤t≤1000),表示测试用例的数量。 每个测试用例包含两行: - 第一行包含两个整数n和c(1≤n≤2×10^5;1≤c≤10^9),分别表示传送器的数量和你的硬币数。 - 第二行包含n个整数a_1, a_2, ..., a_n(1≤a_i≤10^9),表示使用每个传送器需要花费的硬币数。 保证所有测试用例的n之和不超过2×10^5。 **输出格式**: 对于每个测试用例,输出一行,表示最多可以使用的传送器数量。 **输入输出样例**: **输入样例 #1**: ``` 10 5 6 1 1 1 1 1 8 32 100 52 13 6 9 4 100 35 1 1 5 4 5 4 3 2 1 5 9 2 3 1 4 1 5 8 2 3 1 4 1 4 3 2 3 4 1 4 9 5 4 3 3 2 14 7 5 5 600000000 500000000 400000000 300000000 200000000 100000000 ``` **输出样例 #1**: ``` 2 2 0 1 2 2 1 1 1 2 ```

加入题单

算法标签: