CF BUDDY
← Problems·

1955C · Inhabitant of the Deep Sea

1300 · greedy, implementation, math

Problem: nn ships set out to explore the depths of the ocean. The ships are numbered from 11 to nn and follow each other in ascending order; the ii-th ship has a durability of aia_i.

The Kraken attacked the ships kk times in a specific order. First, it attacks the first of the ships, then the last, then the first again, and so on.

Each attack by the Kraken reduces the durability of the ship by 11. When the durability of the ship drops to 00, it sinks and is no longer subjected to attacks (thus the ship ceases to be the first or last, and the Kraken only attacks the ships that have not yet sunk). If all the ships have sunk, the Kraken has nothing to attack and it swims away.

For example, if n=4n=4, k=5k=5, and a=[1,2,4,3]a=[1, 2, 4, 3], the following will happen:

  1. The Kraken attacks the first ship, its durability becomes zero and now a=[2,4,3]a = [2, 4, 3];
  2. The Kraken attacks the last ship, now a=[2,4,2]a = [2, 4, 2];
  3. The Kraken attacks the first ship, now a=[1,4,2]a = [1, 4, 2];
  4. The Kraken attacks the last ship, now a=[1,4,1]a = [1, 4, 1];
  5. The Kraken attacks the first ship, its durability becomes zero and now a=[4,1]a = [4, 1].

How many ships were sunk after the Kraken's attack?

Input Format: The first line contains an integer tt (1t1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains two integers nn and kk (1n21051 \le n \le 2 \cdot 10^5, 1k10151 \le k \le 10^{15}) — the number of ships and how many times the Kraken will attack the ships.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai1091 \le a_i \le 10^9) — the durability of the ships.

It is guaranteed that the sum of nn for all test cases does not exceed 21052 \cdot 10^5.

Output Format: For each test case, output the number of ships sunk by the Kraken on a separate line.

Sample Cases

Case 1

Input

6
4 5
1 2 4 3
4 6
1 2 4 3
5 20
2 7 1 8 2
2 2
3 2
2 15
1 5
2 7
5 2

Output

2
3
5
0
2
2

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback