第 1124 场 Codeforces Round(Div. 1)
A
K 很重要
K Is Important
Codeforces
1200
原题
←B →

K 很重要AI (CI翻译)

You are given an array $a$ consisting of $n$ positive integers, as well as an integer parameter $k$.

给定一个由 $n$ 个正整数组成的数组 $a$,以及一个整数参数 $k$。AI (CI翻译)

While the array has at least $k$ elements, you need to perform one of the following two types of operations on $a$:

当数组中至少有 $k$ 个元素时,你需要对 $a$ 执行以下两种操作之一:AI (CI翻译)

  • Remove $a_k$ and add its value to your score, or
  • Remove $a_{m-k+1}$ and add its value to your score, where $m$ is the length of $a$ before this operation.
  • 删除 $a_k$,并将其值加入得分;或
  • 删除 $a_{m-k+1}$,并将其值加入得分,其中 $m$ 是执行此次操作前 $a$ 的长度。
AI (CI翻译)

After removing an element, the remaining elements keep their relative order.

删除一个元素后,其余元素的相对顺序保持不变。AI (CI翻译)

Your task is to determine the maximum possible score that can be obtained.

你的任务是确定能够获得的最大得分。AI (CI翻译)

Input

输入格式

AI (CI翻译)

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

每个输入包含多组测试用例。第一行包含测试用例数 $t$($1 \le t \le 10^4$)。接下来是各测试用例的描述。AI (CI翻译)

The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 10^5$) — the length of $a$ and the parameter.

每个测试用例的第一行包含两个整数 $n$ 和 $k$($1 \le k \le n \le 10^5$)——数组 $a$ 的长度和参数。AI (CI翻译)

The second line contains $n$ integers $a_i$ ($1 \le a_i \le 10^9$) — the elements of $a$.

第二行包含 $n$ 个整数 $a_i$($1 \le a_i \le 10^9$)——数组 $a$ 的元素。AI (CI翻译)

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.

保证所有测试用例中 $n$ 的总和不超过 $10^5$。AI (CI翻译)

Output

输出格式

AI (CI翻译)

For each test case, output a single integer — the maximum score that can be obtained.

对于每个测试用例,输出一个整数——能够获得的最大得分。AI (CI翻译)

Note

说明

AI (CI翻译)

In the first test case, we can first remove $a_3 = 3$. The score becomes $3$, and the array becomes $[1, 2, 4]$. Then we remove $a_2 = 2$, so the score becomes $5$, and the array becomes $[1, 4]$. Finally, we remove $a_2 = 4$, and the score becomes $9$. Now the length of the array is less than $k=2$, so no more operations can be performed. It can be proven that the maximum score is $9$.

在第一个测试用例中,我们可以先删除 $a_3 = 3$。此时得分为 $3$,数组变为 $[1, 2, 4]$。接着删除 $a_2 = 2$,得分变为 $5$,数组变为 $[1, 4]$。最后删除 $a_2 = 4$,得分变为 $9$。此时数组长度小于 $k=2$,因此无法继续操作。可以证明,最大得分为 $9$。AI (CI翻译)

In the second test case, we can only perform one operation, either removing $a_1 = 3$ or $a_4 = 2$. Obviously, it is better to remove $a_1 = 3$ to get a score of $3$.

在第二个测试用例中,我们只能执行一次操作:删除 $a_1 = 3$ 或 $a_4 = 2$。显然,删除 $a_1 = 3$ 更好,得分为 $3$。AI (CI翻译)

样例

Input #1
4
4 2
1 2 3 4
4 4
3 4 1 2
1 1
1
6 3
1 4 8 2 6 3
Output #1
9
3
1
19
InputCopy OutputCopy
题目信息
题号
2268A
时间限制
2 s
内存限制
256 MB
标签
构造
贪心

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