A sports fest
Practice
3.5 (13 votes)
Sorting
Algorithms
Advanced sorting
Greedy algorithms
Problem
91% Success 1486 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
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 \(X_i\) while that of B is \(Y_i\). 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
- \(1 \leq T \leq 20000\)
- \(1 \leq N \leq 200000\)
- \(1 \leq X_i,Y_i \leq 10^9\)
- Sum of \(N\) over all test cases will not exceed 200000
Submissions
Please login to view your submissions
Similar Problems
Points:30
4 votes
Tags:
Ad-HocRecursionSortingEasy-Medium
Points:30
11 votes
Tags:
SortingAlgorithmsEasy-MediumSorting
Points:30
3 votes
Tags:
AlgorithmsEasy-MediumSorting
Editorial