Codeforces Round 508 (Div. 2)
C
Gambling
Codeforces
1300
原题
← BD →
翻译中…

Two players A and B have a list of $n$ integers each. They both want to maximize the subtraction between their score and their opponent's score.

翻译中…

In one turn, a player can either add to his score any element from his list (assuming his list is not empty), the element is removed from the list afterward. Or remove an element from his opponent's list (assuming his opponent's list is not empty).

翻译中…

Note, that in case there are equal elements in the list only one of them will be affected in the operations above. For example, if there are elements $\{1, 2, 2, 3\}$ in a list and you decided to choose $2$ for the next turn, only a single instance of $2$ will be deleted (and added to the score, if necessary).

翻译中…

The player A starts the game and the game stops when both lists are empty. Find the difference between A's score and B's score at the end of the game, if both of the players are playing optimally.

翻译中…

Optimal play between two players means that both players choose the best possible strategy to achieve the best possible outcome for themselves. In this problem, it means that each player, each time makes a move, which maximizes the final difference between his score and his opponent's score, knowing that the opponent is doing the same.

翻译中…

Input

翻译中…

The first line of input contains an integer $n$ ($1 \le n \le 100\,000$) — the sizes of the list.

翻译中…

The second line contains $n$ integers $a_i$ ($1 \le a_i \le 10^6$), describing the list of the player A, who starts the game.

翻译中…

The third line contains $n$ integers $b_i$ ($1 \le b_i \le 10^6$), describing the list of the player B.

翻译中…

Output

翻译中…

Output the difference between A's score and B's score ($A-B$) if both of them are playing optimally.

翻译中…

Note

翻译中…

In the first example, the game could have gone as follows:

翻译中…
  • A removes $5$ from B's list.
  • B removes $4$ from A's list.
  • A takes his $1$.
  • B takes his $1$.
翻译中…

Hence, A's score is $1$, B's score is $1$ and difference is $0$.

翻译中…

There is also another optimal way of playing:

翻译中…
  • A removes $5$ from B's list.
  • B removes $4$ from A's list.
  • A removes $1$ from B's list.
  • B removes $1$ from A's list.
翻译中…

The difference in the scores is still $0$.

翻译中…

In the second example, irrespective of the moves the players make, they will end up with the same number of numbers added to their score, so the difference will be $0$.

翻译中…

样例

Input #1
2
1 4
5 1
Output #1
0
InputCopy OutputCopy
Input #2
3
100 100 100
100 100 100
Output #2
0
InputCopy OutputCopy
Input #3
2
2 1
5 6
Output #3
-3
InputCopy OutputCopy
题目信息
题号
1038C
时间限制
2 s
内存限制
256 MB
标签
贪心
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。