eolymp
bolt
Try our new interface for solving problems
Problems

Coffee Central

Coffee Central

Is it just a fad or is it here to stay? You're not sure, but the steadily increasing number of coffee shops that are opening in your hometown has certainly become quite a draw. Apparently, people have become so addicted to coffee that apartments that are close to many coffee shops will actually fetch higher rents. This has come to the attention of a local real-estate company. They are interested in identifying the most valuable locations in the city in terms of their proximity to large numbers of coffee shops. They have given you a map of the city, marked with the locations of coffee shops. Assuming that the average person is willing to walk only a fixed number of blocks for their morning coffee, you have to find the location from which one can reach the largest number of coffee shops. As you are probably aware, your hometown is built on a square grid layout, with blocks aligned on north-south and east-west axes. Since you have to walk along streets, the distance between intersections (\textbf{a}, \textbf{b}) and (\textbf{c}, \textbf{d}) is \textbf{|a - c|+|b - d|}. \InputFile The input contains several test cases. Each test case describes a city. The first line of each test case contains four integers \textbf{dx}, \textbf{dy}, \textbf{n}, and \textbf{q}. These are the dimensions of the city grid \textbf{dx}×\textbf{d}y (\textbf{1} ≤ \textbf{dx}, \textbf{dy} ≤ \textbf{1000}), the number of coffee shops \textbf{n} (\textbf{0} ≤ \textbf{n} ≤ \textbf{5·10^5}), and the number of queries \textbf{q} (\textbf{1} ≤ \textbf{q} ≤ \textbf{20}). Each of the next \textbf{n} lines contains two integers \textbf{x_i} and \textbf{y_i} (\textbf{1} ≤ \textbf{x_i} ≤ \textbf{dx}, \textbf{1} ≤ \textbf{y_i} ≤ \textbf{dy}); these specify the location of the \textbf{i}^th coffee shop. There will be at most one coffee shop per intersection. Each of the next \textbf{q} lines contains a single integer \textbf{m} (\textbf{0} ≤ \textbf{m} ≤ \textbf{10^6}), the maximal distance that a person is willing to walk for a cup of coffee. The last test case is followed by a line containing four zeros. \OutputFile For each test case in the input, display its case number. Then display one line per query in the test case. Each line displays the maximum number of coffee shops reachable for the given query distance \textbf{m} followed by the optimal location. For example, the sample output shows that \textbf{3} coffee shops are within query distance \textbf{1} of the optimal location (\textbf{3}, \textbf{4}), \textbf{4} shops are within query distance \textbf{2} of optimal location (\textbf{2}, \textbf{2}), and \textbf{5} shops are within query distance \textbf{4} of optimal location (\textbf{3}, \textbf{1}). If there are multiple optimal locations, pick the location that is furthest south (minimal positive integer \textbf{y}-coordinate). If there is still a tie, pick the location furthest west (minimal positive integer \textbf{x}-coordinate). Follow the format of the sample output.
Time limit 15 seconds
Memory limit 256 MiB
Input example #1
4 4 5 3
1 1
1 2
3 3
4 4
2 4
1
2
4
0 0 0 0
Output example #1
Case 1:
3 (3,4)
4 (2,2)
5 (3,1)
Source ICPC 2011 World Finals