Hide

Problem G
Ban or Pick, What's the Trick

Bobo has recently learned how to play Dota2. Part of the game involves teams selecting some heroes to play and banning other heroes from play. For the sake of this problem, the mechanism of banning/picking heroes is modified and simplified as follows.

Suppose a game is played between two teams: Team A and Team B. Each team has a hero pool of $n$ heroes with positive utility scores $a_1,\dots ,a_ n$ and $b_1,\dots ,b_ n$, respectively.

The two teams then perform ban/pick operations alternately, with Team A going first. In one team’s turn, it can either pick a hero for itself, or ban an unselected hero from the opponent’s hero pool. Note, each of the $2n$ heroes in the lists are distinct (so a ban applies to only one entry), though some may have the same utility score.

After $2n$ turns, all heroes are either picked or banned. Each team then needs to choose at most $k$ heroes from all heroes it picked to form a warband and the score for the warband is calculated as the sum of utility scores over all heroes in it.

Let $s_ A, s_ B$ be the score of the warband formed by Team A and Team B, respectively. Team A wants to maximize the value of $s_ A-s_ B$ while Team B wants to minimize it.

Bobo wants to know what what the final value of $s_ A-s_ B$ will be if both teams act optimally? He is not really good at calculating this, so he turned to you for help.

\includegraphics[scale=0.4]{bpdota2.jpg}
An example of banning/picking heroes in Dota2. Source: TI10 True Sight

Input

The first line contains two integers $n,k(1\leq n\leq 10^5,1\leq k \leq 10)$. The second line contains $n$ integers $a_1,a_2,\dots ,a_ n$ $(1\leq a_ i\leq 10^8)$, denoting the utility score of heroes for Team A. The third line contains $n$ integers $b_1,b_2,\dots ,b_ n$ $(1\leq b_ i\leq 10^8)$, denoting the utility score of heroes for Team B.

Output

Output a single line containing the value of $s_ a - s_ B$ if both players play optimally.

Sample Input 1 Sample Output 1
2 1
3 6
2 4
2
Sample Input 2 Sample Output 2
4 1
1 3 5 7
2 4 6 8
0
Sample Input 3 Sample Output 3
4 2
4 6 7 9
2 5 8 10
3

Please log in to submit a solution to this problem

Log in