CF1862E.Kolya and Movie Theatre

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Recently, Kolya found out that a new movie theatre is going to be opened in his city soon, which will show a new movie every day for nn days. So, on the day with the number 1≤i≤n1 \le i \le n, the movie theatre will show the premiere of the ii-th movie. Also, Kolya found out the schedule of the movies and assigned the entertainment value to each movie, denoted by aia_i.

However, the longer Kolya stays without visiting a movie theatre, the larger the decrease in entertainment value of the next movie. That decrease is equivalent to d⋅cntd \cdot cnt, where dd is a predetermined value and cntcnt is the number of days since the last visit to the movie theatre. It is also known that Kolya managed to visit another movie theatre a day before the new one opened — the day with the number 00. So if we visit the movie theatre the first time on the day with the number ii, then cntcnt — the number of days since the last visit to the movie theatre will be equal to ii.

For example, if d=2d = 2 and a=[3,2,5,4,6]a = [3, 2, 5, 4, 6], then by visiting movies with indices 11 and 33, cntcnt value for the day 11 will be equal to 1−0=11 - 0 = 1 and cntcnt value for the day 33 will be 3−1=23 - 1 = 2, so the total entertainment value of the movies will be a1−d⋅1+a3−d⋅2=3−2⋅1+5−2⋅2=2a_1 - d \cdot 1 + a_3 - d \cdot 2 = 3 - 2 \cdot 1 + 5 - 2 \cdot 2 = 2.

Unfortunately, Kolya only has time to visit at most mm movies. Help him create a plan to visit the cinema in such a way that the total entertainment value of all the movies he visits is maximized.

最近,科里亚得知他的城市即将新开一家电影院,该影院将在接下来的 nn 天内每天上映一部新电影。因此,在编号为 1≤i≤n1 \le i \le n 的第 ii 天,该影院将上映第 ii 部电影的首映式。此外,科里亚还了解了所有电影的排片表,并为每部电影赋予了一个娱乐价值,记为 aia_i。

然而,科里亚距离上一次观影的时间越长,下一部电影的娱乐价值衰减就越严重。该衰减值等于 d⋅cntd \cdot cnt,其中 dd 是一个预先给定的常数,cntcnt 是自上一次观影以来所经过的天数。已知科里亚在这家新影院开业前一天(即编号为 00 的那天)曾去过另一家影院。因此,若他首次观影安排在编号为 ii 的那天,则当天的 cntcnt(即距上一次观影的天数)就等于 ii。

例如,若 d=2d = 2,且 a=[3,2,5,4,6]a = [3, 2, 5, 4, 6],那么若他选择在第 11 天和第 33 天观影,则第 11 天的 cnt=1−0=1cnt = 1 - 0 = 1,第 33 天的 cnt=3−1=2cnt = 3 - 1 = 2,因此总娱乐价值为 a1−d⋅1+a3−d⋅2=3−2⋅1+5−2⋅2=2a_1 - d \cdot 1 + a_3 - d \cdot 2 = 3 - 2 \cdot 1 + 5 - 2 \cdot 2 = 2。

不幸的是,科里亚最多只能观看 mm 部电影。请帮他制定一个观影计划,使得他所观看的所有电影的总娱乐价值最大化。

输入格式

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

The first line of each test case contains three integers nn, mm, and dd (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5, 1≤m≤n1 \le m \le n, 1≤d≤1091 \le d \le 10^9).

The second line of each set of input data contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (−109≤ai≤109-10^9 \le a_i \le 10^9) — the entertainment values of the movies.

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 和 dd(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5,1≤m≤n1 \le m \le n,1≤d≤1091 \le d \le 10^9)。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(−109≤ai≤109-10^9 \le a_i \le 10^9),表示各部电影的娱乐值。

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

输出格式

For each test case, output a single integer — the maximum total entertainment value that Kolya can get.

对于每个测试用例,输出一个整数——Kolya 能获得的最大总娱乐值。

输入输出样例

  • 输入#1

    6
    5 2 2
    3 2 5 4 6
    4 3 2
    1 1 1 1
    6 6 6
    -82 45 1 -77 39 11
    5 2 2
    3 2 5 4 8
    2 1 1
    -1 2
    6 3 2
    -8 8 -2 -1 9 0

    输出#1

    2
    0
    60
    3
    0
    7

说明/提示

The first test case is explained in the problem statement.

In the second test case, it is optimal not to visit any movies.

In the third test case, it is optimal to visit movies with numbers 22, 33, 55, 66, so the total entertainment value of the visited movies will be 45−6⋅2+1−6⋅1+39−6⋅2+11−6⋅1=6045 - 6 \cdot 2 + 1 - 6 \cdot 1 + 39 - 6 \cdot 2 + 11 - 6 \cdot 1 = 60.

第一个测试用例已在题目描述中说明。

在第二个测试用例中,最优策略是不观看任何电影。

在第三个测试用例中,最优策略是观看编号为 22、33、55、66 的电影,因此所观看电影的总娱乐值为 45−6⋅2+1−6⋅1+39−6⋅2+11−6⋅1=6045 - 6 \cdot 2 + 1 - 6 \cdot 1 + 39 - 6 \cdot 2 + 11 - 6 \cdot 1 = 60。

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

首页