CF1684D.Traps

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are nn traps numbered from 11 to nn. You will go through them one by one in order. The ii-th trap deals aia_i base damage to you.

Instead of going through a trap, you can jump it over. You can jump over no more than kk traps. If you jump over a trap, it does not deal any damage to you. But there is an additional rule: if you jump over a trap, all next traps damages increase by 11 (this is a bonus damage).

Note that if you jump over a trap, you don't get any damage (neither base damage nor bonus damage). Also, the bonus damage stacks so, for example, if you go through a trap ii with base damage aia_i, and you have already jumped over 33 traps, you get (ai+3)(a_i + 3) damage.

You have to find the minimal damage that it is possible to get if you are allowed to jump over no more than kk traps.

共有 nn 个陷阱,编号从 11 到 nn。你将按顺序依次经过这些陷阱。第 ii 个陷阱对你造成 aia_i 点基础伤害。

你也可以选择跳过某个陷阱而不经过它。你最多可以跳过 kk 个陷阱。若你跳过某个陷阱,则该陷阱不会对你造成任何伤害。但存在一条额外规则:每当你跳过一个陷阱,其后所有未跳过的陷阱所造成的伤害均增加 11(即额外伤害)。

注意:若你跳过某个陷阱,则你不会受到该陷阱的任何伤害(既无基础伤害,也无额外伤害)。此外,额外伤害具有叠加性;例如,若你经过第 ii 个陷阱(其基础伤害为 aia_i),且此前已跳过了 33 个陷阱,则你将受到 (ai+3)(a_i + 3) 点伤害。

你需要求出:在最多跳过 kk 个陷阱的前提下,所能承受的最小总伤害。

输入格式

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1001 \le t \le 100) — the number of test cases. Description of the test cases follows.

The first line of each test case contains two integers nn and kk (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5, 1≤k≤n1 \le k \le n) — the number of traps and the number of jump overs that you are allowed to make.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^9) — base damage values of all traps.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤1001 \le t \le 100),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 kk(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5,1≤k≤n1 \le k \le n),分别表示陷阱的数量以及允许的跳跃次数。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \le a_i \le 10^9),表示所有陷阱的基础伤害值。

保证所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case output a single integer — the minimal total damage that it is possible to get if you are allowed to jump over no more than kk traps.

对于每个测试用例,输出一个整数——即在最多跳过 kk 个陷阱的前提下,所能受到的最小总伤害。

输入输出样例

  • 输入#1

    5
    4 4
    8 7 1 4
    4 1
    5 10 11 5
    7 5
    8 2 5 15 11 2 8
    6 3
    1 2 3 4 5 6
    1 1
    7

    输出#1

    0
    21
    9
    6
    0

说明/提示

In the first test case it is allowed to jump over all traps and take 00 damage.

In the second test case there are 55 ways to jump over some traps:

  1. Do not jump over any trap.

    Total damage: 5+10+11+5=315 + 10 + 11 + 5 = 31.

  2. Jump over the 11-st trap.

    Total damage: 0‾+(10+1)+(11+1)+(5+1)=29\underline{0} + (10 + 1) + (11 + 1) + (5 + 1) = 29.

  3. Jump over the 22-nd trap.

    Total damage: 5+0‾+(11+1)+(5+1)=235 + \underline{0} + (11 + 1) + (5 + 1) = 23.

  4. Jump over the 33-rd trap.

    Total damage: 5+10+0‾+(5+1)=215 + 10 + \underline{0} + (5 + 1) = 21.

  5. Jump over the 44-th trap.

    Total damage: 5+10+11+0‾=265 + 10 + 11 + \underline{0} = 26.

To get minimal damage it is needed to jump over the 33-rd trap, so the answer is 2121.

In the third test case it is optimal to jump over the traps 11, 33, 44, 55, 77:

Total damage: 0+(2+1)+0+0+0+(2+4)+0=90 + (2 + 1) + 0 + 0 + 0 + (2 + 4) + 0 = 9.

在第一个测试用例中,允许跳过所有陷阱,造成 00 点伤害。

在第二个测试用例中,共有 55 种跳过部分陷阱的方式:

  1. 不跳过任何陷阱。

    总伤害:5+10+11+5=315 + 10 + 11 + 5 = 31。

  2. 跳过第 11 个陷阱。

    总伤害:0‾+(10+1)+(11+1)+(5+1)=29\underline{0} + (10 + 1) + (11 + 1) + (5 + 1) = 29。

  3. 跳过第 22 个陷阱。

    总伤害:5+0‾+(11+1)+(5+1)=235 + \underline{0} + (11 + 1) + (5 + 1) = 23。

  4. 跳过第 33 个陷阱。

    总伤害:5+10+0‾+(5+1)=215 + 10 + \underline{0} + (5 + 1) = 21。

  5. 跳过第 44 个陷阱。

    总伤害:5+10+11+0‾=265 + 10 + 11 + \underline{0} = 26。

为获得最小伤害,需跳过第 33 个陷阱,因此答案为 2121。

在第三个测试用例中,最优策略是跳过第 11、33、44、55、77 个陷阱:

总伤害:0+(2+1)+0+0+0+(2+4)+0=90 + (2 + 1) + 0 + 0 + 0 + (2 + 4) + 0 = 9。

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

首页