CF BUDDY
← Problems·

1995B1 · Bouquet (Easy Version)

1100 · binary search, brute force, greedy

Problem: This is the easy version of the problem. The only difference is that in this version, the flowers are specified by enumeration.

A girl is preparing for her birthday and wants to buy the most beautiful bouquet. There are a total of nn flowers in the store, each of which is characterized by the number of petals, and a flower with kk petals costs kk coins. The girl has decided that the difference in the number of petals between any two flowers she will use in her bouquet should not exceed one. At the same time, the girl wants to assemble a bouquet with the maximum possible number of petals. Unfortunately, she only has mm coins, and she cannot spend more. What is the maximum total number of petals she can assemble in the bouquet?

Input Format: Each test consists of several test cases. The first line contains a single integer tt (1t100001 \le t \le 10\,000) — the number of test cases. This is followed by descriptions of the test cases.

The first line of each test case contains two integers nn, mm (1n2105,1m10181 \le n \le 2 \cdot 10^5, 1 \le m \le 10^{18}) — the number of flowers in the store and the number of coins the girl possesses, respectively. The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1091 \le a_i \le 10^9), where aia_i is the number of petals of the ii-th flower in the store.

The sum of nn over all test cases does not exceed 21052 \cdot {10}^5.

Output Format: For each test case, output a single integer — the maximum possible number of petals in the bouquet that the girl can assemble while meeting all the conditions listed above.

Note: In the first test case, you can assemble a bouquet with (1,1,2,2),(2,2,3),(1,1),(2,2)(1, 1, 2, 2), (2, 2, 3), (1, 1), (2, 2). The maximum over all valid bouquets not greater than 1010 is 77 for (2,2,3)(2, 2, 3). In the third test case, you can assemble a bouquet with only one flower of any type, so the answer is 610610. In the fourth test case, you can assemble a bouquet with (4,4,5)(4, 4, 5), which gives you 1313 petals, and it is the maximum amount of petals that the girl can buy.

Sample Cases

Case 1

Input

5
5 10
1 1 2 2 3
8 20
4 2 7 5 6 1 1 1
8 100000
239 30 610 122 24 40 8 2
11 13
2 4 11 1 1 2 3 5 4 3 2
8 1033
206 206 206 207 207 207 207 1000

Output

7
13
610
13
1033

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