#P5925. [POI 2007] 天然气管道Gaz
[POI 2007] 天然气管道Gaz
Background
Mary is trying to control Chengdu’s natural gas market.
Problem Description
Experts have marked the best natural gas wells and transfer stations on a map of Chengdu. Now we need to connect the transfer stations and the natural gas wells.
Each transfer station must be connected to exactly one well, and vice versa.
Mary specifically requires that every gas pipeline must start from some natural gas well and be built only to the south or to the east.
Mary wants to know how to connect each natural gas well and transfer station so that the total length of the required pipelines is minimal. A solution is guaranteed to exist.
Input Format
The first line contains a positive integer , the number of natural gas wells (the number of transfer stations is the same).
The next lines each contain two integers and , the coordinates of a natural gas well. Moving east increases the coordinate, and moving north increases the coordinate.
The next lines each contain two integers and , the coordinates of a transfer station.
Output Format
The first line contains one number, the minimum total length of the connecting pipelines.
3
3 5
1 2
4 3
6 3
5 2
2 1
9
Hint
For of the testdata, , 。
Translated by ChatGPT 5