AmazonOA #36
Amazon Security Analysis (Min Distance Matching)
估计简单可在线判题
Match n centers with n destinations one-to-one; each pair costs the absolute difference of their coordinates. Find the minimum total cost.
输入格式
The first line contains n (1..100000), the second line contains n center coordinates, and the third line contains n destination coordinates, all in 1..10⁹.
输出格式
Output a single integer, the answer.
样例 1
输入:
3
1 2 2
5 2 4
输出:
6
样例 2
输入:
1
1
9
输出:
8
样例 3
输入:
2
4 1
1 4
输出:
0
样例说明
Example 1: after sorting, pair 1→2, 2→4 and 2→5, for a distance of 1+2+3=6. Example 2: the only distance is 8. Example 3: identical coordinates are paired with each other, costing 0.