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$是执行此操作前数组的长度。
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$),表示数组中的元素。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翻译)
样例
4
4 2
1 2 3 4
4 4
3 4 1 2
1 1
1
6 3
1 4 8 2 6 3
9
3
1
19
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。