問題一覧 > 通常問題

No.2354 Poor Sight in Winter

レベル : / AI推定難易度 : 1725 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 126
作問者 : 👑 AngrySadEight / テスター : kumakuma Shirotsume
お気に入りにしたユーザー ProblemId : 9451 / 自分の提出
問題文最終更新日: 2023-06-17 00:13:26
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 393 (順位表) の他の問題:

Problem Statement

In winter, visibility in the country of yuki can become very poor because of blizzards, so people travel by relying on lights. Specifically, when the visibility is $P$, a traveler repeatedly chooses one lit coordinate whose Manhattan distance from the current coordinate is at most $P$ and moves there.

There are $N$ jizo statues in the country of yuki. The $i$-th jizo statue is at coordinate $(x_i, y_i)$, and all jizo statues have lights on.

You work at a company in the country of yuki, located at coordinate $(s_x, s_y)$. Your home is at coordinate $(g_x, g_y)$. Both the company and your home have lights on.

You have $K$ lights, and you want to place them on any lattice points of the two-dimensional coordinate plane (coordinates whose values are all integers) and turn them on.

Find the minimum value of the visibility with which you can get from the company to your home, when the places to set the lights are chosen appropriately.

Here, the Manhattan distance between $2$ coordinates $(a_1, b_1), (a_2, b_2)$ is defined as $|a_1 - a_2| + |b_1 - b_2|$.

It can also be shown that the answer is always an integer.

Constraints

  • All inputs are integers.
  • $1 \leq N \leq 500$
  • $0 \leq K \leq 10^5$
  • $0 \leq s_x, s_y, g_x, g_y \leq 10^5$
  • $(s_x, s_y) \neq (g_x, g_y)$
  • $0 \leq x_i, y_i \leq 10^5$
  • $(x_i, y_i) \neq (x_j, y_j) (i \neq j)$
  • $(x_i, y_i) \neq (s_x, s_y)$
  • $(x_i, y_i) \neq (g_x, g_y)$

Input

The input is given from standard input in the following format.

$N$ $K$
$s_x$ $s_y$ $g_x$ $g_y$
$x_1$ $y_1$
$x_2$ $y_2$
$\cdots$
$x_N$ $y_N$

Output

Output the answer as an integer.

Sample

Sample 1
Input
1 1
0 0 6 6
2 2
Output
4

When $P \geq 4$, by placing a light at coordinate $(4,4)$, you can go from the company to your home by moving in the order of coordinates $(0,0) \rightarrow (2,2) \rightarrow (4,4) \rightarrow (6,6)$.

When $P < 4$, you cannot get from the company to your home no matter which coordinate the light is placed at, so the answer is $4$.

Sample 2
Input
1 0
0 0 10 10
0 10
Output
10

Note that there may be no new lights that can be placed.

Sample 3
Input
2 16
0 0 100000 100000
8 11
2017 45145
Output
11757

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。