Programming contests

ECN programozó csapatverseny, 2023. november 25.

November 25, 2023 10:30 AM – November 25, 2023 3:30 PM

Hamilton

Santa Claus has decided this year to start delivering Christmas gifts on time, with the help of his elves.

His favorite elf, named Hamilton, needs to traverse a 10000-meter-long, 15-meter-wide stretch of road, where the coordinates (x, y) of each mailbox are precisely known (0 ≤ x ≤ 10 000, 0 ≤ y ≤ 15, x and y are natural numbers).

For any two mailboxes (xa, ya) and (xb, yb), the abscissas are different (xa ≠ xb). And, of course, this condition cannot be fulfilled for the ordinates ya and yb. Hamilton, the elf, has to distribute approximately 4000 packages and would like to carry the packages to mailboxes in such a way that he travels the shortest distance in a single round trip, placing each package in the corresponding mailbox. In other words, the abscissas of the mailboxes continuously increase in the first segment and then continuously decrease. The length of the road should be measured from the left side, starting from the first mailbox, and it should end in the start point.

The requirement for the task is to calculate, given the coordinates of the mailboxes, the shortest distance starting from the first mailbox.

Input Specification

The first line of the input contains the number of mailboxes n. This is followed by n lines, each containing two natural numbers x and y, separated by a space, representing the coordinates of a mailbox.

Output Specification

A single real number should be printed, representing the length of the shortest route, with exactly 6 decimals.

Sample Input

  1. 5
  2. 4 5
  3. 1 1
  4. 6 5
  5. 5 3
  6. 9 1
download as text file

Output for Sample Input

  1. 20.944272
download as text file

Explanation

Hamilton, the elf, travels the following path from mailbox to mailbox:

5 + 2 + 5 + 4.47213595 + 4.47213595 = 20.944272 (with 6 decimals precision).

University of Debrecen; Faculty of Informatics; v. 03/01/2019