Fire Tower
Time limit1sMemory limit128 MB
Place a vertical tower on a polygonal mountain chain and find the smallest height whose top sees every point above the terrain.
- Level
Hard8 of 10
- Topics
- Geometry, Binary search
- Solved
- No attempts yet
Problem
A mountainous region suffered many forest fires during last year's dry season. Before this year's dry season begins, you want to build a single fire tower from which every slope of the mountain range can be watched. To keep the construction cost as low as possible, you want the height of the tower to be as small as possible.
A polyhedral terrain can be thought of as the surface of a mountain range made of flat faces, with no curves and no overhangs. In this problem we consider only the two-dimensional case, which simplifies the terrain into a single polygonal chain in the plane. The chain is given by vertices in increasing order of -coordinate, together with edges, where edge connects the two adjacent vertices and for .
The figure below shows the minimum-height fire tower for one polygonal chain.

The tower is built vertically on the terrain, and its base may lie on any vertex or any edge of the chain. Compute the smallest possible height of the tower such that every point of the chain is visible from the top of the tower. A point of the terrain is visible from the top of the tower when the straight segment never goes below the terrain. You may assume that the minimum height is never .
Input
The input is read from standard input. The first line contains the number of test cases . Each test case begins with a line containing an integer , the number of vertices, where . Each of the next lines contains two integers and , the coordinates of one vertex, where . The vertices are given with distinct, strictly increasing -coordinates.
Output
For each test case, print a single line containing the minimum height of the fire tower that can watch the whole polygonal chain, rounded to one digit after the decimal point. If this minimum height is greater than , print IMPOSSIBLE instead.