Watchdog
Time limit1sMemory limit128 MB
Find an integer roof point where a leash can be tied so the dog reaches every hatch but the leash never crosses the roof edge.
- Level
Medium6 of 10
- Topics
- Geometry, Brute force, Binary search, Implementation
- Solved
- No attempts yet
Problem
A company owns an office building with a perfectly square, flat roof that has several hatches. After a series of burglaries in which the intruders entered through these hatches, the company decided to guard the hatches with a watchdog.
To keep the dog from falling off the roof, one end of a leash is attached to the dog's collar and the other end is fastened to a point on the roof. If the leash is too short the dog cannot reach every hatch; if it is too long the dog can fall off the building. The leash has a hook at each end, so none of its length is used for knots (its full length is exactly how far the dog can reach).
The company wants both of the following to hold:
- The dog can reach the center of every hatch (the dog reaches exactly as far as the leash would reach if it lay flat on the roof).
- The leash never extends beyond the edge of the roof (reaching exactly to the edge is allowed).
A leash may only be fastened at a point with integer coordinates. If the building is meters, the south-west corner is and the north-east corner is . A leash cannot be fastened at a point that holds a hatch.
If there is no point where the leash can be fastened so that the dog reaches every hatch without the leash extending beyond the roof, this breed of dog cannot be used.
Input
The first line contains the number of test cases .
Each test case begins with a line containing two integers and . is the side length of the square roof in meters; it is even and . is the number of hatches, .
The next lines each contain two integers and , the coordinates of a hatch. A hatch never lies outside the roof or on the roof's perimeter, and no two hatches share the same position.
Output
For each test case, print on one line the coordinates of a point at which the leash can be fastened so that the dog reaches every hatch without the leash extending beyond the edge of the roof.
If several points are possible, print the one with the smallest ; if several remain, print the one with the smallest among those.
If no such point exists, print poodle for that test case.