CF1440B.Sum of Medians

传统题 时间 2000 ms 内存 256 MiB 4 尝试 1 已通过 1 标签

Sum of Medians

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.

Input

The first line contains a single integer tt (1t1001 \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 (1n,k10001 \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} (0ai1090 \leq a_i \leq 10^9) — given array. It is guaranteed that the array is non-decreasing: a1a2anka_1 \leq a_2 \leq \ldots \leq a_{nk}.

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

Output

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

Note

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]$. 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.

Samples

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
165
108
145
234
11
3

在线编程 IDE

建议全屏模式获得最佳体验