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.