Codeforces Round 980 (Div. 2) |
---|
Finished |
There is a vending machine that sells lemonade. The machine has a total of $$$n$$$ slots. You know that initially, the $$$i$$$-th slot contains $$$a_i$$$ cans of lemonade. There are also $$$n$$$ buttons on the machine, each button corresponds to a slot, with exactly one button corresponding to each slot. Unfortunately, the labels on the buttons have worn off, so you do not know which button corresponds to which slot.
When you press the button corresponding to the $$$i$$$-th slot, one of two events occurs:
After pressing, the can drops out so quickly that it is impossible to track from which slot it fell. The contents of the slots are hidden from your view, so you cannot see how many cans are left in each slot. The only thing you know is the initial number of cans in the slots: $$$a_1, a_2, \ldots, a_n$$$.
Determine the minimum number of button presses needed to guarantee that you receive at least $$$k$$$ cans of lemonade.
Note that you can adapt your strategy during the button presses based on whether you received a can or not. It is guaranteed that there are at least $$$k$$$ cans of lemonade in total in the machine. In other words, $$$k \leq a_1 + a_2 + \ldots + a_n$$$.
Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \leq k \leq 10^9$$$) — the number of slots in the machine and the required number of cans of lemonade.
The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the number of cans in the slots.
It is guaranteed that $$$k \leq a_1 + a_2 + \ldots + a_n$$$, meaning there are at least $$$k$$$ cans of lemonade in the machine.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, output a single integer — the minimum number of button presses needed to guarantee that you receive at least $$$k$$$ cans of lemonade.
52 11 12 21 23 42 1 310 501 1 3 8 8 9 12 13 27 272 10000000001000000000 500000000
1 2 5 53 1000000000
In the first test case, we can simply press the first button and receive one can of lemonade.
In the second test case, we can press each button once and guarantee that we receive $$$2$$$ cans of lemonade. Note that if we simply press one button twice, we might not be lucky, and that button could correspond to the first slot, in which case we would only receive $$$1$$$ can of lemonade for two presses.
In the third test case, one of the optimal strategies is as follows:
Press the first button twice. After the first press, a can of lemonade will definitely drop out. Then there are two options:
It can be shown that it is impossible to guarantee receiving $$$4$$$ cans of lemonade with only $$$4$$$ presses, so the answer is $$$5$$$.
Name |
---|