Problem J
Freebies Distribution
It’s hackathon season - finally time for Samuele to shine, and show all of his friends that he still has what it takes to grab some freebies.
Samuele knows the location of each of the other $N$ contestants, the $i$-th one being in coordinate $(R_ i, C_ i)$, while Samuele’s location is coordinate $(X, Y)$. There can be multiple contestants in the same coordinate.
Once the freebies distribution is announced, Samuele knows that each contestant will immediately move to the closest booth, choosing the leftmost one in case of a tie. Moving in the grid can only happen horizontally or vertically, and it takes one second to move by one in either direction.
Given this information, Samuele wants to optimize his strategy, maximing his chance of being able to choose the best available freebie: he will go to the booth that minimizes the amount of people getting there before him. If he gets at the booth at the same time as another contestant, his kindness will prevail and he will let them choose first.
Help him by computing the minimum amount of people that will reach the chosen booth before or at the same time as him.
Input
The first line contains one integer $M$, the number of booths.
The second line contains $M$ integers $B_ i$, each being the column coordinate of the $i$-th booth.
The third line contains two integers $X$ and $Y$, respectively the row and column of Samuele’s location.
The fourth line contains one integer $N$, the number of other contestants.
The next $N$ lines contain two integers $R_ i$ and $C_ i$, respectively the row and column of the $i$-th contestant.
Output
You need to write a single line containing a single integer: the minimum number of contestant that will make it to the booth at least as early as Samuele.
Constraints
-
$1 \le N \le 10^{6}$.
-
$1 \le M \le 10^{6}$.
-
$0 \le B_ i < 10^{9}$, for all $i$ in $[0, M-1]$.
-
All values $B_ i$ are distinct.
-
$0 \le R_ i, C_ i, X, Y < 10^{9}$, for all $i$ in $[0, N-1]$.
Example
In the first example below, there’s only one person that would get to the booth in $(0, 3)$ before Samuele.
Sample Input 1 | Sample Output 1 |
---|---|
3 7 3 0 4 0 5 3 1 4 8 1 0 2 3 3 6 |
1 |