负载不均衡AI (CI翻译)
Note the unusually low time limit.
注意时间限制异常严格。AI (CI翻译)
You are given a sequence $a$ of length $n$, as well as an integer $k$.
给定一个长度为 $n$ 的序列 $a$,以及一个整数 $k$。AI (CI翻译)
You may first reorder the elements of $a$ however you like. Then, define $f(a)$ as follows:
你可以先以任意方式重新排列 $a$ 中的元素。然后,定义 $f(a)$ 如下:AI (CI翻译)
- Let
$b$be an array of length$k$which is initially all zeros. - For each
$1 \le i \le n$in order, add$a_i$to any minimum element of$b$. - At the end of this process,
$f(a) = \max(b)$.
- 令
$b$为一个长度为$k$且初始时所有元素均为零的数组。 - 按顺序遍历每个
$1 \le i \le n$,将$a_i$加到$b$中任意一个最小的元素上。 - 完成这一过程后,
$f(a) = \max(b)$。
Find the maximum possible value of $f(a)$ among all rearrangements of $a$.
求在所有 $a$ 的排列中,$f(a)$ 可能达到的最大值。AI (CI翻译)
Input
输入格式
AI (CI翻译)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.
每个测试包含多个测试用例。第一行包含测试用例的数量 $t$($1 \le t \le 10^4$)。接下来是各个测试用例的描述。AI (CI翻译)
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 18$).
每个测试用例的第一行包含两个整数 $n$ 和 $k$($1 \le k \le n \le 18$)。AI (CI翻译)
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
每个测试用例的第二行包含 $n$ 个整数 $a_1, a_2, \ldots, a_n$($1 \le a_i \le 10^9$)。AI (CI翻译)
It is guaranteed that the sum of $2^n$ over all test cases does not exceed $2^{18}$.
保证所有测试用例的 $2^n$ 之和不超过 $2^{18}$。AI (CI翻译)
Output
输出格式
AI (CI翻译)For each test case, output a single integer — the maximum possible value of $f(a)$ among all rearrangements of $a$.
对于每个测试用例,输出一个整数,即在所有 $a$ 的排列中,$f(a)$ 可能达到的最大值。AI (CI翻译)
Note
说明
AI (CI翻译)In the first test case of the second example, one optimal rearrangement of $a$ is $[1, 4, 2, 5]$. $f(a)$ is computed as follows:
在第二个样例的第一个测试用例中,$a$ 的一种最优排列为 $[1, 4, 2, 5]$。$f(a)$ 的计算过程如下:AI (CI翻译)
$i$$a_i$$b$$-$$-$$[0, 0]$$1$$1$$[1, 0]$$2$$4$$[1, 4]$$3$$2$$[3, 4]$$4$$5$$[8, 4]$
$i$$a_i$$b$$-AI (CI翻译)$$-$$[0, 0]$$1$$1$$[1, 0]$$2$$4$$[1, 4]$$3$$2$$[3, 4]$$4$$5$$[8, 4]$
After this, $f(a) = \max([8,4]) = 8$. It can be shown that the maximum achievable $f(a)$ is $8$.
此时,$f(a) = \max([8,4]) = 8$。可以证明,$f(a)$ 能达到的最大值为 $8$。AI (CI翻译)
In the third test case of the second example, one optimal rearrangement of $a$ is $[3, 1, 2, 3, 5, 4, 3, 4]$.
在第二个样例的第三个测试用例中,$a$ 的一种最优排列为 $[3, 1, 2, 3, 5, 4, 3, 4]$。AI (CI翻译)
样例
1
18 5
837492015 264819073 519603847 902746518 173058264 648291507 395174620 781532946 506847193 924613708 158397042 673029415 240785631 819456270 461302987 730619824 528947163 894271056
2823249283
6
4 2
1 2 4 5
1 1
10
8 3
3 4 1 3 2 4 5 3
3 1
1000000000 1000000000 1000000000
17 6
6 7 67 4 1 41 6 9 69 3 1 4 1 5 9 2 6
2 2
1 2
8
10
11
3000000000
85
2
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。