CF1415E.New Game Plus!

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Wabbit is playing a game with nn bosses numbered from 11 to nn. The bosses can be fought in any order. Each boss needs to be defeated exactly once. There is a parameter called boss bonus which is initially 00.

When the ii-th boss is defeated, the current boss bonus is added to Wabbit's score, and then the value of the boss bonus increases by the point increment cic_i. Note that cic_i can be negative, which means that other bosses now give fewer points.

However, Wabbit has found a glitch in the game. At any point in time, he can reset the playthrough and start a New Game Plus playthrough. This will set the current boss bonus to 00, while all defeated bosses remain defeated. The current score is also saved and does not reset to zero after this operation. This glitch can be used at most kk times. He can reset after defeating any number of bosses (including before or after defeating all of them), and he also can reset the game several times in a row without defeating any boss.

Help Wabbit determine the maximum score he can obtain if he has to defeat all nn bosses.

瓦比特正在玩一个包含 nn 个 Boss 的游戏,这些 Boss 编号为 11 到 nn。Boss 可以以任意顺序挑战,每个 Boss 恰好需要被击败一次。游戏中有一个称为“Boss 加成”的参数,初始值为 00。

当击败第 ii 个 Boss 时,当前的 Boss 加成值会加到瓦比特的得分中,随后 Boss 加成值增加 cic_i(即点数增量)。注意:cic_i 可能为负数,这意味着后续 Boss 所提供的分数将减少。

然而,瓦比特在游戏中发现了一个漏洞:在任意时刻,他都可以重置当前流程,开启一次“新游戏+”(New Game Plus)流程。该操作会将当前 Boss 加成值重置为 00,但所有已被击败的 Boss 仍保持已击败状态。当前得分也会被保留,不会因该操作而归零。此漏洞最多可使用 kk 次。他可以在击败任意数量的 Boss 后(包括尚未击败任何 Boss 之前,或击败全部 Boss 之后)执行重置;此外,他也可以连续多次重置而不击败任何 Boss。

请帮助瓦比特计算:在必须击败全部 nn 个 Boss 的前提下,他所能获得的最高得分是多少?

输入格式

The first line of input contains two spaced integers nn and kk (1≤n≤5⋅1051 \leq n \leq 5 \cdot 10^5, 0≤k≤5⋅1050 \leq k \leq 5 \cdot 10^5), representing the number of bosses and the number of resets allowed.

The next line of input contains nn spaced integers c1,c2,…,cnc_1,c_2,\ldots,c_n (−106≤ci≤106-10^6 \leq c_i \leq 10^6), the point increments of the nn bosses.

输入的第一行包含两个用空格分隔的整数 nn 和 kk(1≤n≤5⋅1051 \leq n \leq 5 \cdot 10^5,0≤k≤5⋅1050 \leq k \leq 5 \cdot 10^5),分别表示 Boss 的数量以及允许的重置次数。

第二行输入包含 nn 个用空格分隔的整数 c1,c2,…,cnc_1,c_2,\ldots,c_n(−106≤ci≤106-10^6 \leq c_i \leq 10^6),表示这 nn 个 Boss 所提供的分数增量。

输出格式

Output a single integer, the maximum score Wabbit can obtain by defeating all nn bosses (this value may be negative).

输出一个整数,表示 Wabbit 击败全部 nn 个 Boss 后所能获得的最高得分(该值可能为负数)。

输入输出样例

  • 输入#1

    3 0
    1 1 1

    输出#1

    3
  • 输入#2

    5 1
    -1 -2 -3 -4 5

    输出#2

    11
  • 输入#3

    13 2
    3 1 4 1 5 -9 -2 -6 -5 -3 -5 -8 -9

    输出#3

    71

说明/提示

In the first test case, no resets are allowed. An optimal sequence of fights would be

  • Fight the first boss (+0)(+0). Boss bonus becomes equal to 11.
  • Fight the second boss (+1)(+1). Boss bonus becomes equal to 22.
  • Fight the third boss (+2)(+2). Boss bonus becomes equal to 33.

Thus the answer for the first test case is 0+1+2=30+1+2=3.

In the second test case, it can be shown that one possible optimal sequence of fights is

  • Fight the fifth boss (+0)(+0). Boss bonus becomes equal to 55.
  • Fight the first boss (+5)(+5). Boss bonus becomes equal to 44.
  • Fight the second boss (+4)(+4). Boss bonus becomes equal to 22.
  • Fight the third boss (+2)(+2). Boss bonus becomes equal to −1-1.
  • Reset. Boss bonus becomes equal to 00.
  • Fight the fourth boss (+0)(+0). Boss bonus becomes equal to −4-4.

Hence the answer for the second test case is 0+5+4+2+0=110+5+4+2+0=11.

在第一个测试用例中,不允许重置。一种最优的战斗序列为:

  • 战斗第一位首领 (+0)(+0)。首领奖励变为 11。
  • 战斗第二位首领 (+1)(+1)。首领奖励变为 22。
  • 战斗第三位首领 (+2)(+2)。首领奖励变为 33。

因此,第一个测试用例的答案为 0+1+2=30+1+2=3。

在第二个测试用例中,可以证明一种可能的最优战斗序列为:

  • 战斗第五位首领 (+0)(+0)。首领奖励变为 55。
  • 战斗第一位首领 (+5)(+5)。首领奖励变为 44。
  • 战斗第二位首领 (+4)(+4)。首领奖励变为 22。
  • 战斗第三位首领 (+2)(+2)。首领奖励变为 −1-1。
  • 重置。首领奖励变为 00。
  • 战斗第四位首领 (+0)(+0)。首领奖励变为 −4-4。

因此,第二个测试用例的答案为 0+5+4+2+0=110+5+4+2+0=11。

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

首页