Problem list
Log in
#usaco0161 · USACO 2014-2015 December Silver

Marathon (Silver)

Gold IV 2.0 s 256 MB

Bessie is enrolled in a running class, where she is eventually expected to run a marathon!

The marathon course consists of N checkpoints (3 <= N <= 500) to be visited in sequence, where checkpoint 1 is the start and checkpoint N is the finish. Bessie decides that she will skip up to K checkpoints (K < N) in order to shorten her total journey. She cannot skip checkpoints 1 or N.

Please help Bessie find the minimum distance that she has to run if she can skip up to K checkpoints. The distance between two checkpoints at (x1, y1) and (x2, y2) is the Manhattan distance |x1-x2| + |y1-y2|.

Input

  • Line 1: The values of N and K.
  • Lines 2..1+N: Each line contains two space-separated integers, x and y, representing a checkpoint (-1000 <= x,y <= 1000), in the order they must be visited.

Output

The minimum distance that Bessie can run by skipping up to K checkpoints.

Example 1

Input
5 2
0 0
8 3
1 1
10 -5
2 2
Output
4

Output details: Skipping the checkpoints at (8, 3) and (10, -5) leads to a minimum total distance of 4.

Source
USACO 2014-2015 December Silver
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code