Ironman
Time limit2sMemory limit512 MB
Find the fastest path across n horizontal layers with different speeds, entering and exiting each layer boundary at an optimal x position, and print the minimum travel time.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Math, Geometry, Binary search
- Solved
- No attempts yet
Problem
An ironman triathlon puts the athlete through 3.86 km of swimming, 180.25 km of cycling and a full marathon, and it is one of the hardest races in the sport. Viveka trains for something harder, the n-athlon. In an n-athlon the racers cross several kinds of terrain, water, sand, ice, asphalt, on the way from the starting point to the finishing point, and each racer picks the route that suits her own strengths. Last year Viveka skated the final 40 km over ice in one hour and won, while her rival Veronica sat stuck in a tar pit one metre short of the finish.
The terrain map for this year is out, and Viveka's team wants the fastest route. The race area is flat and is modelled as the plane, measured in metres. It is cut into horizontal layers, and Viveka moves at speed everywhere inside layer , so the time she spends in a layer is the length of her path inside that layer divided by . She may not leave the race area. Compute the smallest time she needs to get from the starting point to the finishing point.
Input
The first line contains four decimal numbers , , , , the coordinates of the starting point and of the finishing point, in metres.
The second line contains one integer (), the number of layers.
The third line contains decimal numbers , the coordinate of each boundary between consecutive layers, given in order, so that . With and , layer is the region . When this line is empty.
The fourth line contains decimal numbers , Viveka's speed in each layer, in metres per second. Every is positive.
Every decimal number in the input has absolute value at most and at most 4 digits after the decimal point.
Output
Print the minimum time in seconds for Viveka to get from the starting point to the finishing point, rounded to exactly 6 digits after the decimal point.