A sports fest

3.5

13 votes
Sorting, Algorithms, Advanced Sorting, Greedy Algorithms
Problem

There are N sports in a college sports fest. There are 2 players A and B, each of the N sports will be chosen by one of them and points that A will get by playing sport i is Xi while that of B is Yi. Now, choice filling has started and A will choose first and each player will be choosing one sport alternatively until they choose all. A and B are rivals and want their score (Sum of A's points - sum of B's score) to be maximized. Find the score of A if they both play optimally.

Input format

  • The first line contains an integer T denoting the number of test cases. 
  • The first line of each test case contains an integer N denoting the number of sports.
  • The second line contains N space-separated integers of array X.
  • The third line contains N space-separated integers of array Y.

Output format

For each test case, print a single line containing the score of A.

Constraints

  • 1T20000
  • 1N200000
  • 1Xi,Yi109
  • Sum of N over all test cases will not exceed 200000
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

A will choose the third sport, B will choose second and A will sum up with first.

Points of A=5+1=6 and B=2. So A's score=6-2=4. Note that this is optimal.

Editor Image

?