QOJ.ac

QOJ

Limite de temps : 2 s Limite de mémoire : 1024 MB Points totaux : 100

#6122. 无法完成的比赛

Statistiques

你是班里 $S$ 名学生的老师。学生编号为 $1$ 到 $S$,第 $i$ 名学生的运动能力为 $A_i$,身高为 $H_i$。

在即将到来的运动会上,你们班将参加一项名为“不可能完成的比赛”的游戏。在这场比赛中,一支队伍的 $N$ 名选手排成一列,用脚踝绑带将他们的腿连接起来(更准确地说,是将第一名选手的右腿与第二名选手的左腿相连,第二名选手的右腿与第三名选手的左腿相连,以此类推),并一起向终点跑去。

作为班主任,你需要从班里挑选 $N$ 名学生作为参赛选手,并决定这 $N$ 名选手的排列顺序。当然,每位选手的运动能力是决定团队实力的关键因素之一。然而,你注意到如果两名相邻选手的身高差异过大,会削弱团队的实力。最终,如果编号为 $r_1, \dots, r_N$ 的学生按此顺序排列,该团队的实力定义如下:

$$\sum_{i=1}^{N} A_{r_i} - \sum_{i=1}^{N-1} |H_{r_i} - H_{r_{i+1}}|$$

你的任务是最大化团队的实力。

输入格式

输入的第一行包含两个整数 $S$ 和 $N$ ($2 \le S \le 10^5$, $2 \le N \le \min(S, 200)$),分别代表班级学生总数和你需要挑选的参赛选手人数。接下来的 $S$ 行,每行包含两个整数 $A_i$ 和 $H_i$ ($1 \le A_i, H_i \le 10^9$),分别代表第 $i$ 名学生的运动能力和身高。

输出格式

输出你能达到的最大团队实力。

样例

样例输入 1

4 2
40 150
100 185
60 160
80 170

样例输出 1

165

样例输入 2

4 3
40 150
100 185
60 160
80 170

样例输出 2

215

样例输入 3

4 3
40 150
100 300
60 160
80 140

样例输出 3

160

样例输入 4

10 5
31 41
59 26
53 58
97 93
23 84
62 64
33 83
27 95
2 84
19 71

样例输出 4

237

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.