QOJ.ac

QOJ

حد الوقت: 3 s حد الذاكرة: 1024 MB مجموع النقاط: 100

#23331. Shelters

الإحصائيات

The village of KOI has $N$ houses on a two-dimensional plane. House $i$ is located at $(X_i,Y_i)$.

The distance between houses $i$ and $j$ is $|X_i-X_j|+|Y_i-Y_j|$, the sum of the differences in their $X$ and $Y$ coordinates. For example, the houses at $(1,6)$ and $(2,4)$ are $(2-1)+(6-4)=3$ units apart.

problem_23331_deff0585bfdfeabceeaf8ceafffce951.png

KOI plans to install shelters in $K$ houses so that residents can evacuate safely during a disaster. To protect everyone, choose the $K$ houses so as to minimize the greatest distance from a house to its nearest shelter, and find that greatest distance.

The figure below shows a village with $5$ houses at $(1,5),(3,0),(3,3),(6,12),(8,9)$.

problem_23331_8cd680fea2cbc249fea162710d3ed8f2.png

Suppose we want to install $2$ shelters. If we place them in the houses at $(3,0)$ and $(1,5)$, the distances from the other three houses to their nearest shelters are $3,11,12$, respectively; the greatest is $12$.

problem_23331_ddd46d198168ba770a17d984bbb13a7d.png

However, if we place shelters at $(3,3)$ and $(6,12)$, the house farthest from its nearest shelter is $(8,9)$, at distance $5$ from $(6,12)$. No placement makes the maximum distance less than $5$, so the desired distance is $5$.

problem_23331_c11b86a1adfd6845fd6e2f0eb63e1681.png

Given the house locations in KOI and the number of shelters to install, find the smallest possible value of the greatest distance from a house to its nearest shelter over all shelter placements.

Constraints

  • All given numbers are integers.
  • $1 \le K \le 3$
  • $K \le N \le 50$
  • $0 \le X_i \le 100\,000$
  • $0 \le Y_i \le 100\,000$
  • No two houses share a location; that is, $(X_1,Y_1),(X_2,Y_2),\ldots,(X_N,Y_N)$ are distinct.

Subtasks

  1. ($5$ points) $N=K+1$
  2. ($7$ points) $K=1$, for every $i$ ($1 \le i \le N$), $X_i=i$ and $Y_i=0$.
  3. ($10$ points) $K=1$
  4. ($18$ points) $K=2$
  5. ($35$ points) $K=3$, for $1 \le i \le N-1$, $X_i<X_{i+1}$, and for every $i$ ($1 \le i \le N$), $Y_i=0$. Thus, $X$ is sorted in ascending order.
  6. ($25$ points) $K=3$

Input

The first line contains $N$ and $K$, separated by a space.

The next $N$ lines give the house locations: the $i$-th line ($1 \le i \le N$) contains $X_i$ and $Y_i$, separated by a space.

Output

Print the answer on the first line.

Examples

Input 1

5 2
1 5
3 0
3 3
6 12
8 9

Output 1

5

Input 2

4 2
0 0
0 5
5 0
5 5

Output 2

5

Input 3

4 1
1 0
2 0
3 0
4 0

Output 3

2

Input 4

2 1
20 23
5 14

Output 4

24

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.