cswork / OA打开练习工作台

AmazonOA #172

Find Minimum Dist.

估计简单可在线判题

考点(AI 标注)贪心调度原地数组

There are n servers and n data centers on a line. Each is used exactly once to form a pair, and the cost of a pair is the absolute difference of their coordinates; minimize the total cost. The one-to-one semantics are established by the source's pairing example: a server cannot be used more than once.

输入格式

The first line contains n, the second line the server coordinates, and the third line the center coordinates. 1≤n≤100000, coordinates 1..10^9.

输出格式

Output a single integer, the answer.

样例 1

输入:

2
1 10
9 2

输出:

2

样例 2

输入:

2
3 3
3 3

输出:

0

样例 3

输入:

1
1
1000000000

输出:

999999999

样例说明

Example 1: 1 pairs with 2 and 10 with 9, total 2. Example 2: all points coincide, cost 0. Example 3: the only possible pairing, distance 999999999.