Perfect Pairing
You are given two arrays A and B, each containing n integers.
You must pair every element of A with exactly one element of B, and every element of B must be used in exactly one pair.
If you pair values x and y, that pair contributes ∣x−y∣ to the total cost.
Find the minimum possible total cost over all perfect pairings.
Input
The first line contains an integer n.
The second line contains n integers a1,a2,…,an.
The third line contains n integers b1,b2,…,bn.
Output
Print one integer: the minimum possible total cost.
Constraints
- 1≤n≤2⋅105
- −109≤ai,bi≤109
Example 1
3
4 1 8
2 9 5
3
Example 2
5
7 -3 12 0 6
10 -1 8 5 -4
6
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.