atcoder#DIVERTA20192B. Picking Up
Picking Up
Score : points
Problem Statement
There are balls in a two-dimensional plane. The -th ball is at coordinates .
We will collect all of these balls, by choosing two integers and such that or and then repeating the following operation:
- Choose a ball remaining in the plane and collect it. Let be the coordinates of this ball. If we collected a ball at coordinates in the previous operation, the cost of this operation is . Otherwise, including when this is the first time to do this operation, the cost of this operation is .
Find the minimum total cost required to collect all the balls when we optimally choose and .
Constraints
- If , or .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum total cost required to collect all the balls.
2
1 1
2 2
1
If we choose , we can collect all the balls at a cost of by collecting them in the order , .
3
1 4
4 6
7 8
1
If we choose , we can collect all the balls at a cost of by collecting them in the order , , .
4
1 1
1 2
2 1
2 2
2