#P9397. 「DBOI」Round 1 DTTM
「DBOI」Round 1 DTTM
Background
Zhang Zeyu and Mu Zhicheng sit on the rooftop, looking at the star-filled sky. In their world, connecting stars is a popular activity. They give it a romantic meaning: if you cannot connect them all, then the one remaining star is the person beside you; if you can connect them all, then both you and the person beside you are stars.
Problem Description
There are stars in the sky. The -th star is located at coordinates . You need to connect the stars to satisfy Zhang Zeyu's requirements below:
- Each star is an endpoint of exactly one line segment, and all segments do not intersect each other (including at endpoints).
- The sum of over all segments, where and are the -coordinates of the left and right endpoints, is minimized.
However, Zhang Zeyu is a bit slow and does not know how to connect them. Mu Zhicheng knows you are the smartest person on Earth, so he gives you the coordinates of the stars. You need to output a connection plan or report that there is no solution.
Input Format
The first line contains , the number of stars.
Starting from the second line, there are lines, each with two integers. Line gives the coordinates of the -th star.
Output Format
On the first line, output the minimum possible value of the sum of over all segments.
Then, on each following line, output two indices, indicating the pair of stars connected by each segment to achieve the minimum value.
If there are multiple valid connection plans, output any one of them. If there is no solution, output on the first line.
4
1 3
2 2
2 1
3 4
2
1 4
2 3
6
1 5
2 3
2 4
2 5
2 -1
3 -3
2
1 3
4 6
2 5
Hint
The solution for Sample 1 is shown in the figure:

The solution for Sample 2 is shown in the figure:

This problem uses bundled testdata and subtask dependencies.
| Special Property | Score | Subtask Dependencies | |||
|---|---|---|---|---|---|
| None | None | ||||
| None | |||||
| None | |||||
Special property : all are equal.
Constraints: For of the testdata, , , and for any , .
Translated by ChatGPT 5