#B. 集训队集合2

    Type: Default 1000ms 256MiB

集训队集合2

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Description

华附可以看成一个网格。

现在有 m 个学生,第 i 个学生在第 xix_i 行 第 yiy_i 列的位置,坐标为 (xi,yi)(x_i, y_i)

现在他们要集合。 每个单位时间,一个学生可以移动一次。 每次移动,可以从 (x,y) 移动到 (x',y') 当且仅当 |x-x'|<=1 并且 |y-y'|<=1。也就是说,每个单位时间,行编号变化要小于等于1,列编号变化也要小于等于1.

例如一个单位时间,可以从(3,4)移动到(2,3),(2,4),(2,5),(3,3),(3,4),(3,5),(4,3),(4,4)或(4,5)。

问集合他们最短需要多少个时间。

Format

Input

第一行,一个整数 m。 接下来 m 行,每行 2 个整数,表示第 i 个学生的坐标。

Output

一个整数,表示需要的时间。

Samples

2
1 2
2 3
1

可以选择在(1,2)集合。第一个学生不动,第二个学生移动到(1,2)。

4
1 2
2 3
3 4
4 5
2

可以选择在(2,3)集合。

Limitation

对于30%的数据,m100m\le 100, 每个学生的坐标数值 在 1~~100之间。

对于60%的数据,每个学生的坐标数值 在 1~~5000之间。

另有20%的数据, m1000m \le 1000

对于100%的数据, m105m \le 10^5,坐标数值在 1~~10910^9 之间。

初一A随堂练习

Not Attended
Status
Done
Rule
IOI
Problem
6
Start at
2025-9-19 10:30
End at
2025-9-19 12:30
Duration
2 hour(s)
Host
Partic.
29