Segment Drawing
Time limit5sMemory limit2048 MB
Each point is paired with a segment on the x-axis. Connect every point to its segment without strict crossings, minimizing total length, or report -1.
Problem
You are given some points, each paired with a line segment. All points lie strictly above the x-axis, and each line segment lies on the x-axis. No two line segments share a point.
For each point and segment pair, draw one new segment that connects the point to its segment. The pairing is fixed, so you cannot change which point connects to which segment.
No two drawn segments may strictly intersect. Two drawn segments may touch at a shared endpoint.
Find the minimum total length of all drawn segments, or determine that no valid drawing exists.
Input
The first line contains a single integer (), the number of point and segment pairs.
Each of the next lines contains four integers , , , (, , ). The line describes a point at and its segment with endpoints and .
The segments are given from left to right. No two segments share a common point. Two points may be at the same location.
Output
Output a single real number, the minimum total length of all drawn segments. An answer is accepted if its absolute or relative error is at most . If the segments cannot be drawn without a strict intersection, output .