Find an integer lattice point on a square roof where a chain can be anchored so it reaches every hatch center without leaving the roof, choosing the smallest coordinates.
Medium6GeometryBrute forceImplementationMathNo attempts yetTime limit1sMemory limit64 MBA company owns an office building downtown. The roof of the building is flat and square. Several hatches are cut into the roof, and they turned out to be a serious security problem. Over the past month the building was broken into several times, and the burglars came in through the roof hatches every time.
The company therefore decided to keep a guard dog on the roof so that nobody gets in through a hatch. The local pet shop tricked the company into taking a very clumsy dog, and on its first visit to the roof the dog came close to falling off the building several times.
So the company decided to keep the dog on a chain, under these conditions:
You choose the length of the chain freely. If the length is L, the dog roams over every point whose distance from the anchor is at most L.
Find the coordinates of a point on the roof where the chain can be anchored.
The first line contains a natural number N≤100, the number of test cases.
The N test cases follow. The first line of each test case contains two integers S and H separated by one space. S is even and 2≤S≤40, and 1≤H≤50. S is the side length of the roof in meters, and H is the number of hatches on the roof.
The next H lines contain two integers X and Y each, the coordinates of the center of the corresponding hatch. A hatch center always lies strictly inside the roof, never on its boundary. No two hatches overlap.
For each test case, print one line with the coordinates X and Y of the anchor point, separated by one space. The point must satisfy every condition in the statement. If several such points exist, print the one with the smallest X coordinate; if several still remain, print the one among them with the smallest Y coordinate.
If no such point exists, print -1 -1 as the answer for that test case.