Problem C

Statement
Copy Copied
C. Make It Beautifultime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given an array $$$a$$$ of $$$n$$$ integers. We define the $$$\text{beauty}$$$ of a number $$$x$$$ to be the number of $$$1$$$ bits in its binary representation. We define the beauty of an array to be the sum of beauties of the numbers it contains. In one operation, you can select an index $$$i$$$ $$$(1 \le i \le n)$$$ and increase $$$a_i$$$ by $$$1$$$. Find the maximum beauty of the array after doing at most $$$k$$$ operations.InputEach test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 5000$$$, $$$0 \le k \le 10^{18}$$$) — the length of the array and the maximal number of operations. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots a_n$$$ ($$$0 \le a_i \le 10^9$$$) —denoting the array $$$a$$$.It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5000$$$.OutputFor each test case, output a single integer, the maximum beauty after at most $$$k$$$ operations.ExampleInput55 20 1 7 2 45 30 1 7 2 41 133 02 0 31 1000000000000Output8
9
2
3
36
NoteIn the first test case, $$$a = [0, 1, 7, 2, 4]$$$.   apply the first operation at $$$i = 1$$$, the new array is $$$a = [1, 1, 7, 2, 4]$$$  apply the second operation at $$$i = 4$$$, the new array is $$$a = [1, 1, 7, 3, 4]$$$  The beauty of this array is $$$1 + 1 + 3 + 2 + 1 = 8$$$. One of the other valid solutions with the same beauty is $$$[0, 1, 7, 3, 5]$$$.In the third test case, $$$a = [3]$$$. Since you are not required to use exactly $$$k$$$ operations, it is optimal to do none.