QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#21104. 马拉松

Statistics

Farmer John 不满意奶牛健康欠佳,给它们报名了各种健身活动。他的优秀奶牛 Bessie 参加了跑步课程,最终需要在农场附近城市的市中心跑一场马拉松!

赛道包含必须依次经过的 $N$ 个检查点,$3 \leq N \leq 500$。检查点 1 是起点,检查点 $N$ 是终点。Bessie 本应逐个经过所有检查点,但她很懒,决定最多跳过 $K$ 个检查点,$K<N$,来缩短路程。她不能跳过检查点 1 或 $N$,否则太容易被发现。

请帮 Bessie 求出最多跳过 $K$ 个检查点时所需跑的最短距离。

市中心街道呈网格状,因此位于 $(x1, y1)$ 和 $(x2, y2)$ 的两个检查点间的距离为 $|x1-x2| + |y1-y2|$。

输入格式

第一行给出 $N$ 和 $K$。

接下来 $N$ 行,每行包含两个由空格分隔的整数 $x$ 和 $y$,表示一个检查点($-1000 \leq x \leq 1000,$ $-1000 \leq y \leq 1000$)。检查点按必须经过的顺序给出。赛道可能多次自交,多个检查点也可能位于同一个位置。跳过这样的检查点时,Bessie 只跳过该次出现,而不是跳过同一位置的所有检查点。

输出格式

输出最多跳过 $K$ 个检查点时的最短距离。在此样例中,跳过 $(8, 3)$ 和 $(10, -5)$ 的检查点能得到最短总距离 4。

样例

输入格式 1

5 2
0 0
8 3
1 1
10 -5
2 2

输出格式 1

4

题目作者:Nick Wu,2014

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.