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$ は飛ばせません。目立ちすぎるからです。

最大 $K$ 個のチェックポイントを飛ばすときに走る最小距離を求めてください。

街の中心部の道路は格子状なので、位置 $(x1, y1)$ と $(x2, y2)$ の間の距離は $|x1-x2| + |y1-y2|$ です。

入力

最初の行には $N$ と $K$ が与えられます。

続く $N$ 行には空白区切りの整数 $x$ と $y$ があり、チェックポイントを表します($-1000 \leq x \leq 1000,$ $-1000 \leq y \leq 1000$)。訪れる順で与えられます。コースは何度も交差し、複数のチェックポイントが同じ場所にある場合があります。その一つを飛ばしても、その出現一つだけを飛ばし、同じ場所のすべてを飛ばすわけではありません。

出力

最大 $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.