#P7194. [COCI 2007/2008 #6] CESTARINE
[COCI 2007/2008 #6] CESTARINE
Problem Description
Luka’s trucks are driving on a highway. There are many entrances and exits on the highway. We consider entrances/exits with the same number to be at the same location.
After entering the highway, a driver receives a slip of paper with their entrance number written on it. When leaving, the toll the driver pays is equal to the absolute difference between the entrance number and the exit number.
Luka is someone who likes to take advantage of small savings. He发现 that even if their routes do not overlap, drivers can exchange their slips on the highway.
However, entering and exiting cannot happen at entrances/exits that are at the same location.
Please write a program to find the minimum total toll.
Input Format
The first line contains a positive integer , the number of trucks.
The next lines each contain two positive integers , representing the entrance number and the exit number.
Output Format
The first line contains a positive integer , the minimum total toll.
3
3 65
45 10
60 25
32
3
5 5
6 7
8 8
5
Hint
Sample #1 Explanation
The minimum total toll is .
Constraints
For of the testdata, , , .
Hint
Please use a -bit integer type (in C / C++ it is long long, in Pascal it is int64), otherwise the answer may be wrong (i.e., Wrong Answer).
Notes
- This problem is worth points in total.
- This problem enables the O2 optimization switch by default.
- Translated from COCI2007-2008 CONTEST #6 T6 CESTARINE, translator https://www.luogu.com.cn/user/219791
Translated by ChatGPT 5