CF2229F.Load Unbalancing

提高+/省选-

通过率:0%

时间限制:1.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Note the unusually low time limit.

You are given a sequence aa of length nn, as well as an integer kk.

You may first reorder the elements of aa however you like. Then, define f(a)f(a) as follows:

  • Let bb be an array of length kk which is initially all zeros.
  • For each 1≤i≤n1 \le i \le n in order, add aia_i to any minimum element of bb.
  • At the end of this process, f(a)=max⁡(b)f(a) = \max(b).

Find the maximum possible value of f(a)f(a) among all rearrangements of aa.

注意:本题的时间限制异常严格。

给定一个长度为 nn 的序列 aa,以及一个整数 kk。

你可以首先以任意方式重排序列 aa 的元素。然后,定义函数 f(a)f(a) 如下:

  • 令 bb 是一个长度为 kk 的数组,初始时所有元素均为 00。
  • 按顺序对每个 1≤i≤n1 \le i \le n,将 aia_i 加到 bb 中任意一个最小元素上。
  • 此过程结束后,定义 f(a)=max⁡(b)f(a) = \max(b)。

求在 aa 的所有重排中,f(a)f(a) 的最大可能值。

输入格式

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

The first line of each test case contains two integers nn and kk (1≤k≤n≤181 \le k \le n \le 18).

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^9).

It is guaranteed that the sum of 2n2^n over all test cases does not exceed 2182^{18}.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 kk(1≤k≤n≤181 \le k \le n \le 18)。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \le a_i \le 10^9)。

保证所有测试用例中 2n2^n 的总和不超过 2182^{18}。

输出格式

For each test case, output a single integer — the maximum possible value of f(a)f(a) among all rearrangements of aa.

对于每个测试用例,输出一个整数——在数组 aa 的所有重排中,f(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 aa is [1,4,2,5][1, 4, 2, 5]. f(a)f(a) is computed as follows:

ii

aia_i

bb

−-

−-

[0,0][0, 0]

11

11

[1,0][1, 0]

22

44

[1,4][1, 4]

33

22

[3,4][3, 4]

44

55

[8,4][8, 4]

After this, f(a)=max⁡([8,4])=8f(a) = \max([8,4]) = 8. It can be shown that the maximum achievable f(a)f(a) is 88.

In the third test case of the second example, one optimal rearrangement of aa is [3,1,2,3,5,4,3,4][3, 1, 2, 3, 5, 4, 3, 4].

在第二个示例的第一个测试用例中,数组 aa 的一种最优重排为 [1,4,2,5][1, 4, 2, 5]。函数 f(a)f(a) 的计算过程如下:

ii

aia_i

bb

−-

−-

[0,0][0, 0]

11

11

[1,0][1, 0]

22

44

[1,4][1, 4]

33

22

[3,4][3, 4]

44

55

[8,4][8, 4]

此后,f(a)=max⁡([8,4])=8f(a) = \max([8,4]) = 8。可以证明,所能达到的最大 f(a)f(a) 值为 88。

在第二个示例的第三个测试用例中,数组 aa 的一种最优重排为 [3,1,2,3,5,4,3,4][3, 1, 2, 3, 5, 4, 3, 4]。

输入解题思路,AI测评打分。不知道怎么写?

首页