#P9895. Battle Royale Airdrop Survival
Battle Royale Airdrop Survival
Battle Royale Airdrop Survival
In the popular battle royale game PUBG an airdrop falls at point \( (x_0, y_0) \) on an infinite 2D plane (where \(x_0\) is an integer and \(y_0\) is given). There are \(n\) players on the field; the i-th player starts at point \( (x_i, y_i) \) (both coordinates are integers). When the game starts, every living player moves synchronously toward the airdrop according to the following rules:
- If a player is already at \( (x_0,y_0) \) at the beginning of a time unit, he stays there collecting supplies.
- If a player is not at \( (x_0,y_0) \), suppose his current position is \( (x,y) \). Then in his move he considers the four adjacent points: \( (x, y-1) \), \( (x, y+1) \), \( (x-1, y) \), and \( (x+1, y) \).
- He chooses one of these points which minimizes the Manhattan distance to \( (x_0,y_0) \), i.e. minimizes \( |x_a-x_0|+|y_a-y_0| \). In case of a tie the following priority is used:
1. \( (x,y-1) \)
2. \( (x,y+1) \)
3. \( (x-1,y) \)
4. \( (x+1,y) \) - At the end of the time unit the player appears at his chosen destination.
Collision rule: At the end of any time unit, if two or more players (who are not at \( (x_0,y_0) \)) find themselves at the same integer coordinate, they all fight and kill each other so that none survive. Note that if multiple players arrive simultaneously at \( (x_0,y_0) \), they are safe.
For each player the path is uniquely determined by the rule. In fact, one may observe that a player first moves vertically to reach row \(y_0\) and then horizontally toward \(x_0\) (since the vertical moves always reduce \(|y-y_0|\) and have priority if \(y\neq y_0\)). More precisely, if a player with starting point \( (x,y) \) has \(y\neq y_0\) then let \(v=|y-y_0|\). He will first take \(v\) vertical moves (each move: if \(y>y_0\) then move to \( (x,y-1) \) and if \(y<y_0\) then move to \( (x,y+1) \)). After that, his horizontal moves are uniquely determined: if \(xx_0\) he moves left; each horizontal move decreases \(|x-x_0|\) by 1. (If \(x=x_0\) the player is already at the drop.)
The twist is that BaoBao does not know \(x_0\) – the horizontal coordinate of the airdrop may be any integer. For a given \(y_0\) and the initial positions of the \(n\) players, BaoBao wonders: over all choices of \(x_0\in\mathbb{Z}\), what are the minimum and maximum possible numbers of players that can successfully arrive and survive at \( (x_0,y_0) \)? A player is considered successful if he eventually reaches \( (x_0,y_0) \) without having been killed in a collision.
Input format note: All coordinates are integers. The Manhattan distance between two points \( (x_a,y_a) \) and \( (x_b,y_b) \) is defined as \( |x_a-x_b|+|y_a-y_b| \). All ties are broken according to the fixed priority order given above.
inputFormat
The first line contains two integers \(n\) and \(y_0\) (the number of players and the known y-coordinate of the airdrop).
Then \(n\) lines follow. The \(i\)-th of these lines contains two integers \(x_i\) and \(y_i\), indicating the starting coordinates of the \(i\)-th player.
outputFormat
Output two integers separated by a space: the minimum possible number of survivors and the maximum possible number of survivors at \( (x_0,y_0) \) over all choices of \(x_0\in\mathbb{Z}\).
sample
3 0
0 0
-1 0
1 0
3 3