You may drop one extra stone anywhere between two river banks so the frog's crossing has the shortest possible longest hop.
Medium7Binary searchGeometryUnion-findGraphNo attempts yetTime limit1sMemory limit256 MBFiona is building a game called Froggy Ford. In it a frog crosses a river by hopping on stones. The river runs between the two straight banks x=0 and x=w, and n stones lie in the water strictly between the banks.
The frog starts at any point of the left bank, lands on stones one after another, and finishes at any point of the right bank. Since the frog takes off from and lands on any point of a bank, a leap between a bank and the stone at (x,y) measures x for the left bank and w−x for the right bank, and a leap straight from one bank to the other measures w. A leap between two stones measures the Euclidean distance between them. A route uses any stones in any order, and the cost of a route is the length of its longest single leap.
The frog is weak, so a player picks the route whose longest leap is as small as possible. Fiona now lets the player drop one more stone into the river before the frog starts. The new stone goes at any real point (x+,y+) with 0<x+<w and −109≤y+≤109, and a route may ignore it.
Over all placements of the new stone and all routes, find the smallest possible length of the longest leap.
| Optimal route | Optimal route with the added stone |
|---|---|
![]() | ![]() |
The first line contains two integers w and n, the width of the river and the number of stones (1≤w≤109, 0≤n≤1000).
Each of the next n lines contains two integers xi and yi, the coordinates of one stone (0<xi<w, −109≤yi≤109). No two stones lie at the same point.
Print the smallest possible length of the longest leap, with exactly three digits after the decimal point. The answer never falls exactly halfway between two consecutive three digit values, so the rounding is unambiguous.