Square in Circles
Time limit8sMemory limit512 MB
Given overlapping circles centered on the x-axis, find the side length of the largest axis-aligned square that fits inside their union.
- Level
Hard8 of 10
- Topics
- Geometry, Binary search
- Solved
- No attempts yet
Problem
Circles Island is completely flat. Its shape is the union of several circles together with their interiors, and every circle has its center on the x-axis.
The king of Circles Island wants to build a large square plaza for the fiftieth anniversary of his accession, and he wants the plaza as large as possible. The whole plaza must lie on the island, and any part of the island may be used. The plaza must be a square, and one of its sides must be parallel to the x-axis.
You are given the center and the radius of every circle that forms the island. Report the side length of the largest square that can be built.
The circles are given in increasing order of the x-coordinate of their centers. For every , circle and circle overlap. No circle is completely covered by the other circles.

Figure 1. The island of the first example and one of its largest squares
Input
The input has several datasets, at most 30 of them. Each dataset is in this format.
N
X1 R1
:
XN RN
The first line of a dataset has one integer , the number of circles that form the island. Line of the next lines has two integers and . Circle has its center at and its radius is .
You may assume the following.
- for every .
- Circle and circle share at least one point for every , that is, .
- Every circle has at least one point that is neither inside nor on the boundary of any other circle.
The end of the input is a line that holds a single zero.
Output
For each dataset, print the side length of the largest square on its own line, rounded to six digits after the decimal point.