CF1791G2.Teleporters (Hard Version)

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

Consider the points 0,1,…,n+10,1,\dots,n+1 on the number line. There is a teleporter located on each of the points 1,2,…,n1,2,\dots,n. At point ii, you can do the following:

  • Move left one unit: it costs 11 coin.
  • Move right one unit: it costs 11 coin.
  • Use a teleporter at point ii, if it exists: it costs aia_i coins. As a result, you can choose whether to teleport to point 00 or point n+1n+1. Once you use a teleporter, you can't use it again.

You have cc coins, and you start at point 00. What's the most number of teleporters you can use?

简单版本与困难版本的唯一区别在于你可以传送至的位置。

考虑数轴上的点 0,1,…,n+10,1,\dots,n+1。在点 1,2,…,n1,2,\dots,n 上各有一个传送器。在点 ii 处,你可以执行以下操作:

  • 向左移动一个单位:花费 11 枚硬币。
  • 向右移动一个单位:花费 11 枚硬币。
  • 使用位于点 ii 的传送器(若存在):花费 aia_i 枚硬币。使用后,你可以选择传送到点 00 或点 n+1n+1。一旦使用过某个传送器,便不能再使用它。

你共有 cc 枚硬币,且起始位置为点 00。你最多能使用多少个传送器?

输入格式

The input consists of multiple test cases. The first line contains an integer tt (1≤t≤10001 \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 nn and cc (1≤n≤2⋅1051 \leq n \leq 2\cdot10^5; 1≤c≤1091 \leq c \leq 10^9) — the length of the array and the number of coins you have respectively.

The following line contains nn space-separated positive integers a1,a2,…,ana_1,a_2,\dots,a_n (1≤ai≤1091 \leq a_i \leq 10^9) — the costs to use the teleporters.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052\cdot10^5.

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 cc(1≤n≤2⋅1051 \leq n \leq 2\cdot10^5;1≤c≤1091 \leq c \leq 10^9),分别表示数组的长度以及你所拥有的金币数量。

接下来的一行包含 nn 个以空格分隔的正整数 a1,a2,…,ana_1,a_2,\dots,a_n(1≤ai≤1091 \leq a_i \leq 10^9),表示使用各传送器所需的费用。

保证所有测试用例中 nn 的总和不超过 2⋅1052\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

说明/提示

In the first test case, you can move one unit to the right, use the teleporter at index 11 and teleport to point n+1n+1, move one unit to the left and use the teleporter at index 55. You are left with 6−1−1−1−1=26-1-1-1-1 = 2 coins, and wherever you teleport, you won'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 n+1n+1, then go three units left and use the teleporter at index 66 to go to n+1n+1, and finally, you go left four times and use the teleporter. The total cost will be 4+6+3+4+4+9=304+6+3+4+4+9 = 30, and you used three teleporters.

In the third test case, you don't have enough coins to use any teleporter, so the answer is zero.

在第一个测试用例中,你可以向右移动一个单位,使用索引为 11 的传送器传送到位置 n+1n+1,再向左移动一个单位,并使用索引为 55 的传送器。此时你剩余 6−1−1−1−1=26-1-1-1-1 = 2 枚硬币;而无论你传送到何处,剩余硬币都不足以再次使用传送器。你共使用了两个传送器,因此答案为二。

在第二个测试用例中,你先向右移动四个单位并使用传送器前往 n+1n+1,接着向左移动三个单位,并使用索引为 66 的传送器前往 n+1n+1,最后向左连续移动四次并使用传送器。总花费为 4+6+3+4+4+9=304+6+3+4+4+9 = 30,且你共使用了三个传送器。

在第三个测试用例中,你没有足够的硬币来使用任何传送器,因此答案为零。

输入解题思路,AI测评打分。不知道怎么写?

首页