Cetinska Road Construction
Time limit1sMemory limit2048 MB
Find the minimum cost of a road between the two ends of a south-to-north river polyline, where each meter of road costs 1 and each river crossing costs T.
- Level
Hard8 of 10
- Topics
- Shortest path, Geometry
- Solved
- No attempts yet
Statement

A river runs through a desert, with a city on each of its two ends. The river is a polyline that starts at one city and ends at the other.
Every straight segment of the river flows strictly from south to north, that is, in the direction of increasing coordinate.
We must build a road connecting the two cities. The road may run along the river, but it cannot simply cross it: a bridge must be built at every crossing. Building one meter of road on the ground costs , and building each bridge (crossing) costs .
Traffic inside the cities is already handled, so the road may start and end on either bank of the river.
Input
The first line contains a natural number (), the number of river vertices (including the cities), and a real number (), the cost of one bridge. has at most two decimal places.
Each of the next lines contains two integers and , the coordinates of the -th river vertex, with . They satisfy for .
No three points in the input are collinear. The road must start at and end at .
Output
Print one number, the minimum possible cost of the project. The answer is accepted if it differs from the exact answer by at most .
Hint
See the figure for the explanation of the first sample.