CF1440B.Sum of Medians

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A median of an array of integers of length nn is the number standing on the ⌈n2⌉\lceil {\frac{n}{2}} \rceil (rounding up) position in the non-decreasing ordering of its elements. Positions are numbered starting with 11. For example, a median of the array [2,6,4,1,3,5][2, 6, 4, 1, 3, 5] is equal to 33. There exist some other definitions of the median, but in this problem, we will use the described one.

Given two integers nn and kk and non-decreasing array of nknk integers. Divide all numbers into kk arrays of size nn, such that each number belongs to exactly one array.

You want the sum of medians of all kk arrays to be the maximum possible. Find this maximum possible sum.

一个长度为 nn 的整数数组的中位数,是指将该数组元素按非递减顺序排列后,位于第 ⌈n2⌉\lceil {\frac{n}{2}} \rceil(向上取整)个位置上的数。位置编号从 11 开始。例如,数组 [2,6,4,1,3,5][2, 6, 4, 1, 3, 5] 的中位数为 33。尽管中位数还有其他定义方式,但在本题中,我们始终采用上述定义。

给定两个整数 nn 和 kk,以及一个长度为 nknk 的非递减整数数组。请将所有数字划分为 kk 个大小均为 nn 的数组,使得每个数字恰好属于其中一个数组。

你希望这 kk 个数组各自的中位数之和尽可能大。求这个可能的最大和。

输入格式

The first line contains a single integer tt (1≤t≤1001 \leq t \leq 100) — the number of test cases. The next 2t2t lines contain descriptions of test cases.

The first line of the description of each test case contains two integers nn, kk (1≤n,k≤10001 \leq n, k \leq 1000).

The second line of the description of each test case contains nknk integers a1,a2,…,anka_1, a_2, \ldots, a_{nk} (0≤ai≤1090 \leq a_i \leq 10^9) — given array. It is guaranteed that the array is non-decreasing: a1≤a2≤…≤anka_1 \leq a_2 \leq \ldots \leq a_{nk}.

It is guaranteed that the sum of nknk for all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1001 \leq t \leq 100),表示测试用例的数量。接下来的 2t2t 行包含各测试用例的描述。

每个测试用例的描述的第一行包含两个整数 nn 和 kk(1≤n,k≤10001 \leq n, k \leq 1000)。

每个测试用例的描述的第二行包含 nknk 个整数 a1,a2,…,anka_1, a_2, \ldots, a_{nk}(0≤ai≤1090 \leq a_i \leq 10^9),即给定的数组。保证该数组是非递减的:a1≤a2≤…≤anka_1 \leq a_2 \leq \ldots \leq a_{nk}。

保证所有测试用例的 nknk 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case print a single integer — the maximum possible sum of medians of all kk arrays.

对于每个测试用例,输出一个整数——所有 kk 个数组的中位数之和的最大可能值。

输入输出样例

  • 输入#1

    6
    2 4
    0 24 34 58 62 64 69 78
    2 2
    27 61 81 91
    4 3
    2 4 16 18 21 27 36 53 82 91 92 95
    3 4
    3 11 12 22 33 35 38 67 69 71 94 99
    2 1
    11 41
    3 3
    1 1 1 1 1 1 1 1 1

    输出#1

    165
    108
    145
    234
    11
    3

说明/提示

The examples of possible divisions into arrays for all test cases of the first test:

Test case 11: [0,24],[34,58],[62,64],[69,78][0, 24], [34, 58], [62, 64], [69, 78]. The medians are 0,34,62,690, 34, 62, 69. Their sum is 165165.

Test case 22: [27,61],[81,91][27, 61], [81, 91]. The medians are 27,8127, 81. Their sum is 108108.

Test case 33: [2,91,92,95],[4,36,53,82],[16,18,21,27][2, 91, 92, 95], [4, 36, 53, 82], [16, 18, 21, 27]. The medians are 91,36,1891, 36, 18. Their sum is 145145.

Test case 44: [3,33,35],[11,94,99],[12,38,67],[22,69,71][3, 33, 35], [11, 94, 99], [12, 38, 67], [22, 69, 71]. The medians are 33,94,38,6933, 94, 38, 69. Their sum is 234234.

Test case 55: [11,41][11, 41]. The median is 1111. The sum of the only median is 1111.

Test case 66: [1,1,1],[1,1,1],[1,1,1][1, 1, 1], [1, 1, 1], [1, 1, 1]. The medians are 1,1,11, 1, 1. Their sum is 33.

第一个测试的所有测试用例中可能的数组划分示例如下:

测试用例 11: [0,24],[34,58],[62,64],[69,78][0, 24], [34, 58], [62, 64], [69, 78]。各数组的中位数分别为 0,34,62,690, 34, 62, 69。它们的和为 165165。

测试用例 22: [27,61],[81,91][27, 61], [81, 91]。各数组的中位数分别为 27,8127, 81。它们的和为 108108。

测试用例 33: [2,91,92,95],[4,36,53,82],[16,18,21,27][2, 91, 92, 95], [4, 36, 53, 82], [16, 18, 21, 27]。各数组的中位数分别为 91,36,1891, 36, 18。它们的和为 145145。

测试用例 44: [3,33,35],[11,94,99],[12,38,67],[22,69,71][3, 33, 35], [11, 94, 99], [12, 38, 67], [22, 69, 71]。各数组的中位数分别为 33,94,38,6933, 94, 38, 69。它们的和为 234234。

测试用例 55: [11,41][11, 41]。该数组的中位数为 1111。唯一中位数的和为 1111。

测试用例 66: [1,1,1],[1,1,1],[1,1,1][1, 1, 1], [1, 1, 1], [1, 1, 1]。各数组的中位数分别为 1,1,11, 1, 1。它们的和为 33。

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

首页