CF1733A.Consecutive Sum

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

Consecutive Sum

You are given an array aa with nn integers. You can perform the following operation at most kk times:

  • Choose two indices ii and jj, in which i  mod  k=j  mod  ki \,\bmod\, k = j \,\bmod\, k (1≤i<j≤n1 \le i \lt j \le n).
  • Swap aia_i and aja_j.

After performing all operations, you have to select kk consecutive elements, and the sum of the kk elements becomes your score. Find the maximum score you can get.

Here x mod yx \bmod y denotes the remainder from dividing xx by yy.

Input

The first line contains one integer tt (1≤t≤6001 \le t \le 600) — the number of test cases.

Each test case consists of two lines.

The first line of each test case contains two integers nn and kk (1≤k≤n≤1001 \le k \le n \le 100) — the length of the array and the number in the statement above.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1090 \le a_i \le 10^9)  — the array itself.

Output

For each test case, print the maximum score you can get, one per line.

Note

In the first test case, we can get a score of 1111 if we select a1,a2a_1, a_2 without performing any operations.

In the third test case, we can get a score of 1515 if we first swap a1a_1 with a4a_4 and then select a3,a4,a5a_3, a_4, a_5.

Samples

5
3 2
5 6 0
1 1
7
5 3
7 0 4 0 4
4 2
2 7 3 4
3 3
1000000000 1000000000 999999997
11
7
15
10
2999999997

在线编程 IDE

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