#P9895. [ICPC 2018 Qingdao R] Airdrop

[ICPC 2018 Qingdao R] Airdrop

题目描述

PUBG is a multiplayer online battle royale video game. In the game, up to one hundred players parachute onto an island and scavenge for weapons and equipment to kill others while avoiding getting killed themselves. Airdrop in this game is a key element, as airdrops often carry with them strong weapons or numerous supplies, helping players to survive.

textit{Airdrop in the game(?)

Consider the battle field of the game to be a two-dimensional plane. An airdrop has just landed at point (x0,y0)(x_0, y_0) (both x0x_0 and y0y_0 are integers), and all the nn players on the battle field, where (xi,yi)(x_i, y_i) (both xix_i and yiy_i are integers) indicates the initial position of the ii-th player, start moving towards the airdrop with the following pattern:

  • If the position of a living player at the beginning of this time unit is not equal to (x0,y0)(x_0, y_0), he will begin his next move.
    • Let's say he is currently at point (x,y)(x, y). For his next move, he will consider four points (x,y1)(x, y - 1), (x,y+1)(x, y + 1), (x1,y)(x - 1, y) and (x+1,y)(x + 1, y).
    • He will select one of the four points whose Manhattan distance to the airdrop (x0,y0)(x_0, y_0) is the smallest to be the destination of his next move. Recall that the Manhattan distance between two points (xa,ya)(x_a, y_a) and (xb,yb)(x_b, y_b) is defined as xaxb+yayb|x_a - x_b| + |y_a - y_b|.
    • If two or more points whose Manhattan distance to the airdrop is the same, he will use the following priority rule to break the tie: (x,y1)(x, y - 1) has the highest priority to be selected, (x,y+1)(x, y + 1) has the second highest priority, (x1,y)(x - 1, y) has the third highest priority, and (x+1,y)(x + 1, y) has the lowest priority.
    • At the end of this time unit, he arrives at his destination.
  • If the position of a living player at the beginning of this time unit is equal to (x0,y0)(x_0, y_0), he will continue to fatten his backpack with the supplies in the airdrop and stays at (x0,y0)(x_0, y_0).

But the battle is tough and it's almost impossible for all the players to arrive at the airdrop safely. If two or more players meet at point (x,y)(x', y') other than (x0,y0)(x_0, y_0), where both xx' and yy' are integers, they will fight and kill each other and none of them survive.

BaoBao is a big fan of the game and is interested in the number of players successfully arriving at the position of the airdrop, but he doesn't know the value of x0x_0. Given the value of y0y_0 and the initial position of each player, please help BaoBao calculate the minimum and maximum possible number of players successfully arriving at the position of the airdrop for all x0Zx_0 \in \mathbb{Z}, where Z\mathbb{Z} is the set of all integers (note that x0x_0 can be positive, zero or negative).

输入格式

There are multiple test cases. The first line of the input contains an integer TT, indicating the number of test cases. For each test case:

The first line contains two integers nn and y0y_0 (1n1051 \le n \le 10^5, 1y01051 \le y_0 \le 10^5), indicating the number of players and the yy value of the airdrop.

For the following nn lines, the ii-th line contains two integers xix_i and yiy_i (1xi,yi1051 \le x_i, y_i \le 10^5), indicating the initial position of the ii-th player.

It's guaranteed that the sum of nn in all test cases will not exceed 10610^6, and in each test case no two players share the same initial position.

输出格式

For each test case output one line containing two integers pminp_\text{min} and pmaxp_\text{max} separated by one space. pminp_\text{min} indicates the minimum possible number of players successfully arriving at the position of the airdrop, while pmaxp_\text{max} indicates the maximum possible number.

3
3 2
1 2
2 1
3 5
3 3
2 1
2 5
4 3
2 3
1 3
4 3
1 3
0 3
2 2

提示

We now explain the first sample test case.

To obtain the answer of pmin=1p_\text{min} = 1, one should consider x0=3x_0 = 3. The following table shows the position of each player at the end of each time unit when x0=3x_0 = 3.

To obtain the answer of pmax=3p_\text{max} = 3, one should consider x0=2x_0 = 2. The following table shows the position of each player at the end of each time unit when x0=2x_0 = 2.