Interesting Couple

시간 제한2초메모리 제한2048 MB

요약
맨해튼 거리를 쓰는 격자 위의 N개 점에서 p(i,j) >= d(i,j)를 만족하는 쌍 (i,j) 중 p(i,j)의 최솟값을 구한다.
난이도

어려움10점 중 8점

유형
분할 정복, 정렬, 기하, 이분 탐색
정답자
아직 제출이 없습니다

문제

You are hosting a party with NN guests (numbered from 11 to NN) in a large room. The party room can be represented as a 22-dimensional Cartesian space where guest ii stands at (X_i,Y_i)(X\_i , Y\_i). Since you have a unique personality, you require each guest to only move horizontally or vertically within this room.

The distance between two guests ii and jj, denoted as d(i,j)d(i, j), is the total distance they need to travel in both horizontal and vertical directions to reach each other, i.e., d(i,j)=∣X_i−Xj∣+∣Y_i−Yj∣d(i, j) = |X\_i - Xj | + |Y\_i - Yj |.

The privacy value of two guests ii and jj, denoted as p(i,j)p(i, j), is determined by their distances to the closest other guest. Formally, p(i,j)p(i, j) is the smallest min⁡(d(i,k),d(j,k))\min(d(i, k), d(j, k)) over all kk where k≠ik \ne i and k≠jk \ne j.

A pair of guest ii and jj is an interesting couple if and only if their privacy value is greater or equal to the distance between them. In other words, it is a pair (i,j)(i, j) such that p(i,j)≥d(i,j)p(i, j) ≥ d(i, j).

Your task in this problem is to find the minimum value of p(i,j)p(i, j) among all such interesting couples.

입력

The first line consists of an integer NN (3≤N≤100,0003 ≤ N ≤ 100\\, 000).

Each of the next NN lines consists of two integers X_iX\_i Y_iY\_i (0≤X_i,Y_i≤1090 ≤ X\_i , Y\_i ≤ 10^9). There are no two guests stand at the same location. Formally, (X_i,Y_i)≠(X_j,Y_j)(X\_i , Y\_i) \ne (X\_j , Y\_j ) for 1≤i<j≤N1 ≤ i < j ≤ N.

Under the given constraints, it can be shown that an interesting couple always exists.

출력

Output an integer representing the minimum value of p(i,j)p(i, j) among all interesting couples.

예제4

  1. 예제 1

    입력
    4
    3 2
    6 4
    3 4
    4 7
    
    예상 출력
    3
    
  2. 예제 2

    입력
    3
    4 6
    8 6
    6 4
    
    예상 출력
    4
    
  3. 예제 3

    입력
    5
    1 5
    2 5
    11 5
    12 5
    20 5
    
    예상 출력
    8
    
  4. 예제 4

    입력
    5
    4 4
    4 3
    4 5
    3 4
    5 4
    
    예상 출력
    1