题库练习 Teleporters (Hard Version)
← 上一题 下一题 →

A15702 | Teleporters (Hard Version)

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

The only difference between the easy and hard versions are the locations you can teleport to.

Consider the points $0,1,\dots,n+1$ 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 can choose whether to teleport to point $0$ or point $n+1$ . 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 positive 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
3
0
1
3
2
1
1
2
2
C++ 编辑器
输入
输出