#P13585. [NWRRC 2023] Every Queen

[NWRRC 2023] Every Queen

题目描述

There are nn chess queens on an infinite grid. They are placed in squares with coordinates (x1,y1),(x2,y2),,(xn,yn)(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 (xi,yi)(x_i, y_i) attacks square (x,y)(x, y) if at least one of the following conditions is satisfied:

  • xi=xx_i = x;
  • yi=yy_i = y;
  • xix=yiy|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 (1t1051 \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 (1n1051 \le n \le 10^5).

The ii-th of the following nn lines contains two integers xix_i and yiy_i, denoting the coordinates of the square containing the ii-th queen (108xi,yi108-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\tt{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 (109x,y109-10^9 \le x, y \le 10^9).

If no such square exists, print a single line containing NO\tt{NO} instead.

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

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