cswork / OA打开练习工作台

AmazonOA #293

Minimize Sum of Absolute Differences

估计简单可在线判题

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

Use every element of two equal-length arrays exactly once to form n pairs. The same position in b cannot be matched by different positions in a, and different positions holding the same value still count as separate elements. Minimize the total of the absolute differences within each pair.

输入格式

The first line contains n, the second line contains a, and the third line contains b. The main raw constraints explicitly say Unknown; this site adds 1≤n≤100000, −10^9≤a[i],b[i]≤10^9. This range does not pretend to be the source's original bounds.

输出格式

Output a single integer, the answer.

样例 1

输入:

2
1 10
9 2

输出:

2

样例 2

输入:

2
-5 2
4 -3

输出:

4

样例 3

输入:

2
3 3
3 3

输出:

0

样例说明

The answers are 2, 4 and 0 respectively. In the second example, pair −5 with −3 and 2 with 4; each pair differs by 2.