CF2268A.K Is Important

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array aa consisting of nn positive integers, as well as an integer parameter kk.

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

  • Remove aka_k and add its value to your score, or
  • Remove am−k+1a_{m-k+1} and add its value to your score, where mm is the length of aa 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.

给你一个由 nn 个正整数组成的数组 aa,以及一个整数参数 kk。

只要数组中至少包含 kk 个元素,你就需要对 aa 执行以下两种操作之一:

  • 删除 aka_k,并将它的值加到你的得分中;或
  • 删除 am−k+1a_{m-k+1},并将它的值加到你的得分中,其中 mm 是本次操作前数组 aa 的长度。

删除一个元素后,其余元素保持其相对顺序不变。

你的任务是确定所能获得的最大可能得分。

输入格式

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

The first line of each test case contains two integers nn and kk (1≤k≤n≤1051 \le k \le n \le 10^5) — the length of aa and the parameter.

The second line contains nn integers aia_i (1≤ai≤1091 \le a_i \le 10^9) — the elements of aa.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 kk(1≤k≤n≤1051 \le k \le n \le 10^5)—— 分别表示数组 aa 的长度和参数。

第二行包含 nn 个整数 aia_i(1≤ai≤1091 \le a_i \le 10^9)—— 即数组 aa 的元素。

保证所有测试用例的 nn 之和不超过 10510^5。

输出格式

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=3a_3 = 3. The score becomes 33, and the array becomes [1,2,4][1, 2, 4]. Then we remove a2=2a_2 = 2, so the score becomes 55, and the array becomes [1,4][1, 4]. Finally, we remove a2=4a_2 = 4, and the score becomes 99. Now the length of the array is less than k=2k=2, so no more operations can be performed. It can be proven that the maximum score is 99.

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

在第一个测试用例中,我们首先移除 a3=3a_3 = 3,得分变为 33,数组变为 [1,2,4][1, 2, 4];接着移除 a2=2a_2 = 2,得分变为 55,数组变为 [1,4][1, 4];最后移除 a2=4a_2 = 4,得分变为 99。此时数组长度已小于 k=2k=2,因此无法再执行任何操作。可以证明,最大得分为 99。

在第二个测试用例中,我们只能执行一次操作,即移除 a1=3a_1 = 3 或 a4=2a_4 = 2。显然,移除 a1=3a_1 = 3 可获得更高的得分 33。

输入解题思路,AI测评打分。不知道怎么写?

首页