luogu#P4771. 八百标兵奔北坡
八百标兵奔北坡
Background
baingbaboom is running north!!!
Problem Description
Now on an map, there are babingbabooms!!! For each point on the map, there is a representing the height of that location. Now these babingbabooms all want to run to a mountain slope in the north. Find the nearest mountain to the north for each babingbaboom.
Additional definitions:
Mountain: a point whose surrounding area has no place higher than it (4-connected).
In the north: Let the babingbaboom's coordinate be and the mountain's coordinate be . The mountain is to the north of the babingbaboom if and only if .
Chebyshev distance:
$A(x_1,y_1) B(x_2,y_2):dis_{A,B}=\max(|x_1 - x_2|, |y_1 - y_2|)$
Input Format
Line contains three positive integers .
Lines to each contain positive integers .
Lines to each contain two positive integers , indicating the coordinate of each babingbaboom.
Output Format
Output lines in total. If for a babingbaboom there exists such a nearest mountain (by Chebyshev distance), output the Chebyshev distance from this babingbaboom to that mountain. Otherwise, output "Pool Babingbaboom!".
5 5 5
1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4
1 2
2 3
3 4
4 5
5 1
Pool Babingbaboom!
Pool Babingbaboom!
1
2
0
Hint
Constraints: , , .
The testdata has gradients.
Sample image (stars represent babingbabooms, red represents mountains):

(The vertical axis is , and the horizontal axis is . I did not pay attention when drawing it, sorry.)
Translated by ChatGPT 5