Codeforces Round 1030 (Div. 2)
C
Make It Beautiful
Codeforces
1300
原题
← BD1 →
翻译中…

You 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.

翻译中…

Input

翻译中…

Each 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$.

翻译中…

Output

翻译中…

For each test case, output a single integer, the maximum beauty after at most $k$ operations.

翻译中…

Note

翻译中…

In 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.

翻译中…

样例

Input #1
5
5 2
0 1 7 2 4
5 3
0 1 7 2 4
1 1
3
3 0
2 0 3
1 100000000000
0
Output #1
8
9
2
3
36
InputCopy OutputCopy
题目信息
题号
2118C
时间限制
2 s
内存限制
512 MB
标签
位运算
数据结构
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。