Signal 1
InterviewTime limit1.5sMemory limit128 MB
Choose a subset of points with distinct x-coordinates; maximize the total Euclidean length of the polyline joining them in increasing x order.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Sorting, Geometry, Math
- Solved
- No attempts yet
Problem
There are signals on the coordinate plane. Signal sits at , and no two signals share a position.
A communication system is built by choosing some of the signals and joining them with segments in order of increasing coordinate. The chosen signals must have pairwise different coordinates. The length of the system is the sum of the Euclidean distances between consecutive signals, and a system built from a single signal has length 0.
Build the communication system of greatest length so that a signal reaches as far as possible, then report that length.
Input
The first line contains the number of signals ().
Each of the next lines contains the coordinates and of one signal, separated by a space (, and and are integers).
No coordinate pair is given twice.
Output
Print the length of the longest communication system on one line, rounded to six digits after the decimal point. Pad with zeros so that six digits always appear.