CF BUDDY
← Problems·

1783C · Yet Another Tournament

1700 · binary search, greedy, sortings

Problem: You are participating in Yet Another Tournament. There are n+1n + 1 participants: you and nn other opponents, numbered from 11 to nn.

Each two participants will play against each other exactly once. If the opponent ii plays against the opponent jj, he wins if and only if i>ji > j.

When the opponent ii plays against you, everything becomes a little bit complicated. In order to get a win against opponent ii, you need to prepare for the match for at least aia_i minutes — otherwise, you lose to that opponent.

You have mm minutes in total to prepare for matches, but you can prepare for only one match at one moment. In other words, if you want to win against opponents p1,p2,,pkp_1, p_2, \dots, p_k, you need to spend ap1+ap2++apka_{p_1} + a_{p_2} + \dots + a_{p_k} minutes for preparation — and if this number is greater than mm, you cannot achieve a win against all of these opponents at the same time.

The final place of each contestant is equal to the number of contestants with strictly more wins ++ 11. For example, if 33 contestants have 55 wins each, 11 contestant has 33 wins and 22 contestants have 11 win each, then the first 33 participants will get the 11-st place, the fourth one gets the 44-th place and two last ones get the 55-th place.

Calculate the minimum possible place (lower is better) you can achieve if you can't prepare for the matches more than mm minutes in total.

Input Format: The first line contains a single 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 mm (1n51051 \le n \le 5 \cdot 10^5; 0mi=1nai0 \le m \le \sum\limits_{i=1}^{n}{a_i}) — the number of your opponents and the total time you have for preparation.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (0ai10000 \le a_i \le 1000), where aia_i is the time you need to prepare in order to win against the ii-th opponent.

It's guaranteed that the total sum of nn over all test cases doesn't exceed 51055 \cdot 10^5.

Output Format: For each test case, print the minimum possible place you can take if you can prepare for the matches no more than mm minutes in total.

Note: In the first test case, you can prepare to all opponents, so you'll win 44 games and get the 11-st place, since all your opponents win no more than 33 games.

In the second test case, you can prepare against the second opponent and win. As a result, you'll have 11 win, opponent 11 — 11 win, opponent 22 — 11 win, opponent 33 — 33 wins. So, opponent 33 will take the 11-st place, and all other participants, including you, get the 22-nd place.

In the third test case, you have no time to prepare at all, so you'll lose all games. Since each opponent has at least 11 win, you'll take the last place (place 66).

In the fourth test case, you have no time to prepare, but you can still win against the first opponent. As a result, opponent 11 has no wins, you have 11 win and all others have at least 22 wins. So your place is 44.

Sample Cases

Case 1

Input

5
4 401
100 100 200 1
3 2
1 2 3
5 0
1 1 1 1 1
4 0
0 1 1 1
4 4
1 2 2 1

Output

1
2
6
4
1

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