CF2268A.K Is Important
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a consisting of n positive integers, as well as an integer parameter k.
While the array has at least k elements, you need to perform one of the following two types of operations on a:
- Remove ak and add its value to your score, or
- Remove am−k+1 and add its value to your score, where m is the length of a before this operation.
After removing an element, the remaining elements keep their relative order.
Your task is to determine the maximum possible score that can be obtained.
给你一个由 n 个正整数组成的数组 a,以及一个整数参数 k。
只要数组中至少包含 k 个元素,你就需要对 a 执行以下两种操作之一:
- 删除 ak,并将它的值加到你的得分中;或
- 删除 am−k+1,并将它的值加到你的得分中,其中 m 是本次操作前数组 a 的长度。
删除一个元素后,其余元素保持其相对顺序不变。
你的任务是确定所能获得的最大可能得分。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains two integers n and k (1≤k≤n≤105) — the length of a and the parameter.
The second line contains n integers ai (1≤ai≤109) — the elements of a.
It is guaranteed that the sum of n over all test cases does not exceed 105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 k(1≤k≤n≤105)—— 分别表示数组 a 的长度和参数。
第二行包含 n 个整数 ai(1≤ai≤109)—— 即数组 a 的元素。
保证所有测试用例的 n 之和不超过 105。
输出格式
For each test case, output a single integer — the maximum score that can be obtained.
对于每个测试用例,输出一个整数——所能获得的最高得分。
输入输出样例
输入#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
输出#1
9 3 1 19
说明/提示
In the first test case, we can first remove a3=3. The score becomes 3, and the array becomes [1,2,4]. Then we remove a2=2, so the score becomes 5, and the array becomes [1,4]. Finally, we remove a2=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.
In the second test case, we can only perform one operation, either removing a1=3 or a4=2. Obviously, it is better to remove a1=3 to get a score of 3.
在第一个测试用例中,我们首先移除 a3=3,得分变为 3,数组变为 [1,2,4];接着移除 a2=2,得分变为 5,数组变为 [1,4];最后移除 a2=4,得分变为 9。此时数组长度已小于 k=2,因此无法再执行任何操作。可以证明,最大得分为 9。
在第二个测试用例中,我们只能执行一次操作,即移除 a1=3 或 a4=2。显然,移除 a1=3 可获得更高的得分 3。
输入解题思路,AI测评打分。不知道怎么写?