After the Contest: Balloons
Time limit1sMemory limit128 MB
Simulate balloons inflated left to right on a line, each stopping at its max radius or when it touches an earlier balloon, and output the final radii efficiently.
- Level
Medium7 of 10
- Topics
- Binary search, Geometry, Stack
- Solved
- No attempts yet
Problem
After finishing the preparations for CEOI 2011, you feel like throwing a party. Actually, more than a party, you want to blow up balloons. There are perfectly spherical balloons lying on the ground.
They have not been inflated yet, so each balloon starts with radius . The -th balloon is fixed at coordinate ; it can neither move nor float away. The balloons are inflated one by one from left to right. Each balloon grows until it reaches its maximum radius , or until it touches another balloon that was inflated earlier.

Figure 1: all balloons of the example after being inflated.
Determine the final radius of every balloon.
Input
The first line contains the number of balloons ().
Each of the next lines describes one balloon: the -th of these lines contains two integers and separated by a space. Here is the coordinate where the balloon sits () and is the maximum radius that balloon may reach (). The balloons are given from left to right and the coordinates are strictly increasing, i.e. .
Output
Print lines. The -th line must contain the final radius of the -th balloon, rounded to exactly decimal places.