Every Queen

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

요약
각 퀸이 같은 행, 같은 열, 또는 같은 대각선 위의 칸을 공격할 때, 모든 퀸이 공격하는 칸을 하나 찾는다.
난이도

보통10점 중 6점

유형
기하, 해시맵, 수학, 구현
정답자
아직 제출이 없습니다

문제

There are nn chess queens on an infinite grid. They are placed in squares with coordinates (x_1,y_1),(x_2,y_2),…,(x_n,y_n)(x\_1, y\_1), (x\_2, y\_2), \ldots, (x\_n, y\_n). Your task is to find a square that all queens attack, or report that no such square exists.

A queen in square (x_i,y_i)(x\_i, y\_i) attacks square (x,y)(x, y) if at least one of the following conditions is satisfied:

  • x_i=xx\_i = x;
  • y_i=yy\_i = y;
  • ∣x_i−x∣=∣y_i−y∣|x\_i - x| = |y\_i - y|.

Note that in this problem, the queens do not block each other. For example, if there are queens in squares (1,1)(1, 1) and (2,2)(2, 2), both of them attack square (3,3)(3, 3). Moreover, you can choose a square that already contains a queen. For example, square (1,1)(1, 1) would be a valid answer in this case.

입력

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1051 \le t \le 10^5). The description of the test cases follows.

The first line of each test case contains a single integer nn, denoting the number of queens (1≤n≤1051 \le n \le 10^5).

The ii-th of the following nn lines contains two integers x_ix\_i and y_iy\_i, denoting the coordinates of the square containing the ii-th queen (−108≤x_i,y_i≤108-10^8 \le x\_i, y\_i \le 10^8). No two queens share the same square.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

출력

For each test case, if an answer exists, print "YES" in the first line. Then, in the second line, print two integers xx and yy, denoting the coordinates of a square attacked by every queen (−109≤x,y≤109-10^9 \le x, y \le 10^9).

If no such square exists, print a single line containing "NO" instead.

It can be shown that if an answer exists, there also exists an answer that satisfies −109≤x,y≤109-10^9 \le x, y \le 10^9. If there are multiple answers, print any of them.

예제1

  1. 예제 1

    입력
    3
    2
    1 1
    2 2
    4
    0 1
    1 0
    3 1
    4 0
    5
    0 1
    1 0
    1 2
    2 2
    4 2
    
    예상 출력
    YES
    1 1
    NO
    YES
    -1 2