Bridge Across Rough Terrain
Time limit1sMemory limit1024 MB
Find two points on the mountain polyline between A and B, at most L apart, so that the horizontal segment joining them never dips below the terrain.
- Level
Medium7 of 10
- Topics
- Geometry, Two pointers, Sliding window
- Solved
- No attempts yet
Statement
The profile of the Ural Mountains is a polyline where . The starting and ending points of the profile are at sea level, so .
Two distinct points and lie on the mountain profile, and a road must be built between them. The road runs along the mountain slopes and a horizontal bridge. The length of the bridge must not exceed . Both ends of the bridge lie on the profile. The road enters the bridge from one end and leaves from the other. The bridge may not contain any point strictly below the polyline, because no tunnels are built.
Input
The first line contains two integers and , where is the number of polyline vertices and is the maximum bridge length. The second line contains the coordinates of point , and the third line contains the coordinates of point . The next lines contain the vertices of the polyline.
All coordinates have absolute value at most . It is guaranteed that , , and that and lie on the polyline. The points and are different.
Output
Print the coordinates of the bridge ends on the first and second lines, with at least 5 digits after the decimal point. If several answers exist, print any of them.

