Problem F. Recycling Bottles

时间限制 2000 ms   内存限制 256 MB

It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.

We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can carry only one bottle at once each.

For both Adil and Bera the process looks as follows:

  1. Choose to stop or to continue to collect bottles.
  2. If the choice was to continue then choose some bottle and walk towards it.
  3. Pick this bottle and walk to the recycling bin.
  4. Go to step 1.

Adil and Bera may move independently. They are allowed to pick bottles simultaneously, all bottles may be picked by any of the two, it's allowed that one of them stays still while the other one continues to pick bottles.

They want to organize the process such that the total distance they walk (the sum of distance walked by Adil and distance walked by Bera) is minimum possible. Of course, at the end all bottles should lie in the recycling bin.

输入数据

First line of the input contains six integers ax, ay, bx, by, tx and ty (0 ≤ ax, ay, bx, by, tx, ty ≤ 109) — initial positions of Adil, Bera and recycling bin respectively.

The second line contains a single integer n (1 ≤ n ≤ 100 000) — the number of bottles on the ground.

Then follow n lines, each of them contains two integers xi and yi (0 ≤ xi, yi ≤ 109) — position of the i-th bottle.

It's guaranteed that positions of Adil, Bera, recycling bin and all bottles are distinct.

输出数据

Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct if c802c7a196476b344b7b5ed47d4ec45f567c6fa7.png.

样例

样例说明

Consider the first sample.

Adil will use the following path: 4542f69d4c5684b025552c6dedd05b493f06a708.png.

Bera will use the following path: 6d1bafc34a5c12b4cbeabd0dc83f78bfa59f09ec.png.

Adil's path will be ac17d331c0e21e3e21fe9ebbf223039c7b521e07.png units long, while Bera's path will be 8a39edd0e49b0e29ff99f919cc3039c25c1a29af.png units long.

"); $(this).append($copy); var clipboard = new Clipboard('#' + cpyId, { text: function(trigger) { return document.querySelector('#' + preId).innerText; } }); var isInput = $(this).parent().hasClass("input"); clipboard.on('success', function(e) { if (isInput) { Codeforces.showMessage("The example input has been copied into the clipboard"); } else { Codeforces.showMessage("The example output has been copied into the clipboard"); } e.clearSelection(); }); }); autosize($('.test-explanation textarea')); });

提交

请先 登录

© 2025 FAQs Contact About