Problem L
Segment Drawing
You’re given some points, paired with an equal number of line segments. All points are strictly above the x-axis. Each line segment lies completely on the x-axis. None of the line segments share any common points.
You would like to draw some new line segments – one for each
given point/line segment pair. The
No two drawn segments may strictly intersect, but it is allowed to have one drawn segment touching another drawn segment at an endpoint.
You would like to find the minimum total length of all drawn segments, or determine that it is impossible to draw such segments.
Input
The first line contains a single integer
Each of the next
Output
Output a single real number, which is the minimum total
length of all drawn segments. The answer will be accepted if it
is within an absolute or relative error of at most
Sample Input 1 | Sample Output 1 |
---|---|
3 0 6 -4 -2 -2 1 -1 0 0 4 1 4 |
11.9995169566 |
Sample Input 2 | Sample Output 2 |
---|---|
3 0 6 -4 -2 0 4 -1 0 -2 1 1 4 |
-1 |
Sample Input 3 | Sample Output 3 |
---|---|
2 0 5 -1000000 -1 0 5 1 1000000 |
10.1980390272 |