Codeforces Round 1118 (Div. 2)
B2
Carrot Chopdown (Hard Version)
Codeforces
1600
原题
← B1C →
翻译中…

This is the hard version of the problem. The difference between the versions is that in this version, you need to solve the problem for different values of $k$. You can hack only if you solved all versions of this problem.

翻译中…

Alp loves carrots. Since he hasn't eaten lunch yet, he wants to buy a carrot salad to eat outside. However, he has a weird obsession: all the carrots must be the exact same length; otherwise, the salad doesn't look aesthetically pleasing to him. Since he is in the middle of the street and doesn't have a knife, he can't cut the carrots himself. You need to divide all the carrots using your machine and sell them to Alp.

翻译中…

You are given $n$ delicious carrots with sizes $a_1, a_2, \ldots, a_n$. You are also given a cutting machine, which works as follows.

翻译中…
  • For each operation, you choose a set of carrots (you can choose chopped carrots again) and a positive integer $x$ (not necessarily the same for each operation).
  • After that, consider every chosen carrot, let its length be $l$. If $l \le x$, this carrot is unaffected; otherwise, it is divided into two carrots of sizes $x$ and $l-x$.
翻译中…

We'll sell some of the final carrots to an interesting guy who wants them all to be the same length.

翻译中…

We are asking you to determine the maximum number of carrots we can sell after using this machine exactly $k$ times. Solve the problem for each $k = 1, 2, \ldots, m$ independently.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains $n$ and $m$ ($1 \le n,m \le 2 \cdot 10^5$), denoting the number of carrots and the maximum possible length of a carrot.

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le m$), denoting the initial carrot sizes.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$ and the sum of $m$ over all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output $m$ integers — the answer for each $k=1, 2, \ldots, m$.

翻译中…

Note

翻译中…

In the first test case, the given carrots are $[1, 2, 3, 4, 4]$.

翻译中…

For $k=1$, it is best to choose $x=2$ with the set $[2, 3, 4, 4]$. After the operation, we'll get $[1, 2, 2, 1, 2, 2, 2, 2]$. We can sell $6$ carrots of length $2$.

翻译中…

For $k=2$, it is best to choose $x=2$ with the set $[2, 3, 4, 4]$. After the operation, we'll get $[1, 2, 2, 1, 2, 2, 2, 2]$. For the second operation, it is best to choose $x=1$ with the set of all of the carrots. Resulting in $14$ carrots, all of the same length. We can sell $14$ carrots of length $1$.

翻译中…

样例

Input #1
6
5 4
1 2 3 4 4
5 8
1 1 8 8 8
1 8
6
7 9
1 7 5 1 7 5 3
4 1
1 1 1 1
3 5
3 1 5
Output #1
6 14 14 14
6 12 26 26 26 26 26 26
2 3 6 6 6 6 6 6
7 17 29 29 29 29 29 29 29
4
3 7 9 9 9
InputCopy OutputCopy
题目信息
题号
2258B2
时间限制
1 s
内存限制
256 MB
标签
暴力
贪心
模拟
数学

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