Codeforces Round 821 (Div. 2)
A
Consecutive Sum
Codeforces
800
原题
←B →
翻译中…

You are given an array $a$ with $n$ integers. You can perform the following operation at most $k$ times:

翻译中…
  • Choose two indices $i$ and $j$, in which $i \,\bmod\, k = j \,\bmod\, k$ ($1 \le i \lt j \le n$).
  • Swap $a_i$ and $a_j$.
翻译中…

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

翻译中…

Here $x \bmod y$ denotes the remainder from dividing $x$ by $y$.

翻译中…

Input

翻译中…

The first line contains one integer $t$ ($1 \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 $n$ and $k$ ($1 \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 $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \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 $11$ if we select $a_1, a_2$ without performing any operations.

翻译中…

In the third test case, we can get a score of $15$ if we first swap $a_1$ with $a_4$ and then select $a_3, a_4, a_5$.

翻译中…

样例

Input #1
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
Output #1
11
7
15
10
2999999997
InputCopy OutputCopy
题目信息
题号
1733A
时间限制
1 s
内存限制
256 MB
标签
贪心
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。