QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 1024 MB Total points: 100

#23331. 避難所

Statistics

2次元平面上の KOI 村には $N$ 軒の家がある。$i$ 番目の家の位置は $(X_i,Y_i)$ である。

$i$ 番目と $j$ 番目の家の距離は $|X_i-X_j|+|Y_i-Y_j|$、すなわち $X$ 座標の差と $Y$ 座標の差の和である。例えば $(1,6)$ と $(2,4)$ の家の距離は $(2-1)+(6-4)=3$ である。

problem_23331_deff0585bfdfeabceeaf8ceafffce951.png

KOI 村は災害時に住民が安全に避難できるよう、$K$ 軒の家に避難所を設ける予定である。全住民の安全を考慮し、各家から最寄りの避難所までの距離の最大値を最小にする $K$ 軒を選び、そのとき最も遠い家から避難所までの距離を求めたい。

下図は $5$ 軒の家が $(1,5),(3,0),(3,3),(6,12),(8,9)$ にある村の例である。

problem_23331_8cd680fea2cbc249fea162710d3ed8f2.png

この村に $2$ か所の避難所を設ける。$(3,0)$ と $(1,5)$ の家を選ぶと、残りの3軒から最寄りの避難所までの距離はそれぞれ $3,11,12$ で、最大は $12$ である。

problem_23331_ddd46d198168ba770a17d984bbb13a7d.png

一方、$(3,3)$ と $(6,12)$ の家に避難所を設けると、最寄りの避難所から最も遠い家は $(8,9)$ で、$(6,12)$ からの距離は $5$ となる。どの配置でも最大距離を $5$ 未満にはできないので、求める距離は $5$ である。

problem_23331_c11b86a1adfd6845fd6e2f0eb63e1681.png

KOI 村の家の位置と設ける避難所の数が与えられたとき、すべての配置の中で、各家から最寄りの避難所までの距離の最大値を最小にしたときの距離を求めよ。

制約

  • 与えられる数はすべて整数である。
  • $1 \le K \le 3$
  • $K \le N \le 50$
  • $0 \le X_i \le 100\,000$
  • $0 \le Y_i \le 100\,000$
  • 同じ位置に複数の家はない。つまり $(X_1,Y_1),(X_2,Y_2),\ldots,(X_N,Y_N)$ は互いに異なる。

小課題

  1. ($5$ 点) $N=K+1$
  2. ($7$ 点) $K=1$, すべての $i$($1 \le i \le N$)について $X_i=i$ かつ $Y_i=0$。
  3. ($10$ 点) $K=1$
  4. ($18$ 点) $K=2$
  5. ($35$ 点) $K=3$, $1 \le i \le N-1$ に対して $X_i<X_{i+1}$ で、すべての $i$($1 \le i \le N$)について $Y_i=0$。つまり $X$ は昇順に整列している。
  6. ($25$ 点) $K=3$

入力

1行目に $N$ と $K$ が空白区切りで与えられる。

続く $N$ 行に家の位置が与えられる。その $i$ 行目($1 \le i \le N$)には $X_i$ と $Y_i$ が空白区切りで与えられる。

出力

1行目に答えを出力せよ。

入出力例

入力 1

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

出力 1

5

入力 2

4 2
0 0
0 5
5 0
5 5

出力 2

5

入力 3

4 1
1 0
2 0
3 0
4 0

出力 3

2

入力 4

2 1
20 23
5 14

出力 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.