Map Labeler
Time limit1sMemory limit128 MB
Given city points in the plane, find the largest square label size so that each label has its city at the midpoint of its top or bottom edge and no two label interiors overlap.
- Level
Hard8 of 10
- Topics
- Binary search, Geometry, Implementation, Brute force
- Solved
- No attempts yet
Problem
Generating a map is a hard problem in cartography, and one crucial part of it is labeling the cities automatically: every city needs a text label placed at its location so that no two labels overlap. In this problem we consider a simplified version of that task.
Model each city as a point in the plane. Its label is a text contained in a square whose edges are parallel to the - and -axes. Each label must be positioned so that the city's point lies exactly at the midpoint of the label's top or bottom edge. In a valid labeling all square labels have the same size, and no two labels overlap in their interiors, although they may touch along an edge.
Given the integer coordinates of every city, find the largest integer label size for which a valid labeling exists.

Input
The first line contains an integer (), the number of test cases. Each test case begins with a line containing an integer (), the number of cities. Each of the following lines contains two integers and (), the - and -coordinates of one city. No two cities share the same coordinates.
Output
For each test case, print one line containing the maximum possible integer label size for a valid labeling.