CF2229F.Load Unbalancing
提高+/省选-
通过率:0%
时间限制:1.50s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Note the unusually low time limit.
You are given a sequence a of length n, as well as an integer k.
You may first reorder the elements of a however you like. Then, define f(a) as follows:
- Let b be an array of length k which is initially all zeros.
- For each 1≤i≤n in order, add ai to any minimum element of b.
- At the end of this process, f(a)=max(b).
Find the maximum possible value of f(a) among all rearrangements of a.
注意:本题的时间限制异常严格。
给定一个长度为 n 的序列 a,以及一个整数 k。
你可以首先以任意方式重排序列 a 的元素。然后,定义函数 f(a) 如下:
- 令 b 是一个长度为 k 的数组,初始时所有元素均为 0。
- 按顺序对每个 1≤i≤n,将 ai 加到 b 中任意一个最小元素上。
- 此过程结束后,定义 f(a)=max(b)。
求在 a 的所有重排中,f(a) 的最大可能值。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains two integers n and k (1≤k≤n≤18).
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109).
It is guaranteed that the sum of 2n over all test cases does not exceed 218.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 k(1≤k≤n≤18)。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)。
保证所有测试用例中 2n 的总和不超过 218。
输出格式
For each test case, output a single integer — the maximum possible value of f(a) among all rearrangements of a.
对于每个测试用例,输出一个整数——在数组 a 的所有重排中,f(a) 的最大可能值。
输入输出样例
输入#1
1 18 5 837492015 264819073 519603847 902746518 173058264 648291507 395174620 781532946 506847193 924613708 158397042 673029415 240785631 819456270 461302987 730619824 528947163 894271056
输出#1
2823249283
输入#2
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
输出#2
8 10 11 3000000000 85 2
说明/提示
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:
i
ai
b
−
−
[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.
In the third test case of the second example, one optimal rearrangement of a is [3,1,2,3,5,4,3,4].
在第二个示例的第一个测试用例中,数组 a 的一种最优重排为 [1,4,2,5]。函数 f(a) 的计算过程如下:
i
ai
b
−
−
[0,0]
1
1
[1,0]
2
4
[1,4]
3
2
[3,4]
4
5
[8,4]
此后,f(a)=max([8,4])=8。可以证明,所能达到的最大 f(a) 值为 8。
在第二个示例的第三个测试用例中,数组 a 的一种最优重排为 [3,1,2,3,5,4,3,4]。
输入解题思路,AI测评打分。不知道怎么写?