Minimum number of total absolute difference

you are given to array containing integers a and b .array is of length n and array b is of length m You need to matches element in a with unique element in b there might be some elements in b that are not matched, but all the elements in a should be matched. so for a configuration the answer is sigma (abs(x-y)) for all the prirs (x,y) where x belongs to a and y belongs to b.
Sample input
2
2
3
1
6
4
Output
6
Explanation
(1,4)(3,6)