CF2264B.Knife's Pill Farm

入门

通过率:0%

时间限制:1.50s

内存限制:256MB

AC君温馨提醒

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

题目描述

Mr. Knife has drafted nn absurd posts for a channel on a chat platform. His goal is to farm pill emoji reactions. Unfortunately, the channel's pill-farming bot uses an unnecessarily elaborate scoring rule.

The drafts have absurdity ratings a1,a2,…,ana_1, a_2, \ldots, a_n, which may be negative. Mr. Knife must publish exactly mm drafts in their original order. Their ratings form a subsequence∗^{\text{∗}} bb of aa with length mm.

His pill score starts at 00. When he publishes the ii-th chosen draft, the bot changes his score by i⋅(bi−bi−1)i \cdot (b_i - b_{i-1}), where b0=0b_0 = 0. A negative change deducts points, and the score is allowed to become negative. Thus, his final pill score is $$ \sum_{i = 1}^{m} i \cdot (b_i - b_{i - 1}). $$

What is the maximum pill score Mr. Knife can obtain by choosing which drafts to publish?

∗^{\text{∗}}A sequence aa is a subsequence of a sequence bb if aa can be obtained from bb by the deletion of several (possibly, zero or all) elements from arbitrary positions.

Mr. Knife 为某聊天平台上的一个频道草拟了 nn 篇荒诞帖子。他的目标是刷取药丸(pill)emoji 反应。不幸的是,该频道的“刷药丸”机器人采用了一种过分复杂的评分规则。

这些草稿的荒诞度评分为 a1,a2,…,ana_1, a_2, \ldots, a_n,该值可能为负数。Mr. Knife 必须按原始顺序恰好发布其中 mm 篇草稿。这些被选中的草稿的评分构成原序列 aa 的一个长度为 mm 的子序列∗^{\text{∗}} bb。

他的药丸得分初始为 00。当他发布第 ii 个被选中的草稿时,机器人会将其得分改变 i⋅(bi−bi−1)i \cdot (b_i - b_{i-1}),其中约定 b0=0b_0 = 0。负向变化将扣除分数,且总分允许为负数。因此,他最终的药丸得分为

∑i=1mi⋅(bi−bi−1).\sum_{i = 1}^{m} i \cdot (b_i - b_{i - 1}).

通过选择发布哪些草稿,Mr. Knife 能获得的最高药丸得分是多少?

∗^{\text{∗}} 序列 aa 称为序列 bb 的一个子序列,若 aa 可通过从 bb 中任意位置删除若干(可能为零个或全部)元素而得到。

输入格式

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 mm (1≤m≤n≤2⋅1051 \le m \le n \le 2 \cdot 10^5) — the number of drafts and the number of posts Mr. Knife must publish.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (−107≤ai≤107-10^7 \le a_i \le 10^7) — the absurdity ratings of the drafts.

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

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

每个测试用例的第一行包含两个整数 nn 和 mm(1≤m≤n≤2⋅1051 \le m \le n \le 2 \cdot 10^5)——分别表示草稿数量和 Mr. Knife 必须发布的帖子数量。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(−107≤ai≤107-10^7 \le a_i \le 10^7)——表示各草稿的荒谬度评分。

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

输出格式

For each test case, print one integer — the maximum pill score Mr. Knife can obtain by publishing exactly mm drafts in their original order.

对于每个测试用例,输出一个整数——即 Mr. Knife 按原始顺序发布恰好 mm 篇草稿所能获得的最大药丸分数。

输入输出样例

  • 输入#1

    6
    5 3
    0 8 1 7 3
    4 3
    0 -4 10 -2
    4 2
    0 5 -2 4
    6 3
    0 9 8 7 6 5
    1 1
    7
    3 2
    5 -100 4

    输出#1

    20
    34
    10
    15
    7
    108

说明/提示

In the first test case, Mr. Knife can publish the drafts with ratings [0,1,7][0, 1, 7]. His final pill score is $$ 1 \cdot (0 - 0) + 2 \cdot (1 - 0) + 3 \cdot (7 - 1) = 20. $$

In the second test case, he can publish the drafts with ratings [0,−4,10][0, -4, 10]. The second post deducts points, but the third post more than makes up for it. His final pill score is $$ 1 \cdot (0 - 0) + 2 \cdot (-4 - 0) + 3 \cdot (10 - (-4)) = 34. $$

在第一个测试用例中,Knife 先生可以发布评分为 [0,1,7][0, 1, 7] 的草稿。他的最终“药丸分数”为

1⋅(0−0)+2⋅(1−0)+3⋅(7−1)=20.1 \cdot (0 - 0) + 2 \cdot (1 - 0) + 3 \cdot (7 - 1) = 20.

在第二个测试用例中,他可以发布评分为 [0,−4,10][0, -4, 10] 的草稿。第二篇帖子会扣分,但第三篇帖子的加分足以弥补并超出。他的最终“药丸分数”为

1⋅(0−0)+2⋅(−4−0)+3⋅(10−(−4))=34.1 \cdot (0 - 0) + 2 \cdot (-4 - 0) + 3 \cdot (10 - (-4)) = 34.

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

首页