Permutations of Two Arrays
Обмеження: 2 сек., 512 МіБ
You are given two sequences: a of length n and b of length m.
Let k=min.
You want to choose a permutation c of the sequence a and a permutation d of the sequence b to maximize the following score: \sum_{i=1}^k |c_i - d_i|.
Вхідні дані
The first line contains two integers n and m – the lengths of the sequences a and b, respectively.
The second line contains n integers a_i.
The third line contains m integers b_i.
Вихідні дані
In the single line print an integer – the maximum score.
Обмеження
1 \le n, m \le 10^5,
0 \le a_i, b_i \le 10^9.
Приклади
Вхідні дані (stdin) | Вихідні дані (stdout) |
---|---|
4 4 4 7 7 4 44 47 4 7 | 86 |
Вхідні дані (stdin) | Вихідні дані (stdout) |
---|---|
4 7 1 2 3 4 10 20 30 40 50 60 70 | 210 |
Примітки
In the first example, we have a = (4, 7, 7, 4), b = (44, 47, 4, 7). When we choose c = (7, 4, 4, 7), d = (7, 47, 44, 4), the score will be |c_1 - d_1| + |c_2 - d_2| + |c_3 - d_3| + |c_4 - d_4| = |7 - 7| + |4 - 47| + |4 - 44| + |7 - 4| = 0 + 43 + 40 + 3 = 86. It is the maximum score.