A cricket tournament

2.7

7 votes
Quick Sort, Sorting, Algorithms
Problem

In a cricket tournament, n matches are supposed to be played between Bob and James.

You are given two arrays A and B. Array A represents the energy levels of Bob and array B represents the energy levels of James. The size of both the arrays is the same as n.

Now, n matches will be played between Bob and James, and for the ith match the energy level at ith index is compared of both. The winner of the ith match will be the one whose energy level at that index is higher.

If Bob wins in the ith match, then the energy level difference (between the ith level of both) will be added to his score else his score remains the same i.e., on losing, Bob's points will not decrease.

Bob wants to maximize his score by changing his energy levels, that is, Bob can make a permutation of his array.

Help Bob in knowing the maximum score he can get.

Input format

  • The first line of each test case contains an integer n denoting the number of matches.
  • Each of the next two lines contains n integers representing energy levels.

Output format

Print a single integer denoting the number of pentagons possible.

Constraints

1n105
1Energy Levels106

 

Sample Input
5
1 2 3 4 5
1 2 3 4 5
Sample Output
6
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Bob will permute his array to {5, 4, 3, 2, 1}. So for the first and second levels, Bob will get a score of 4, 2 respectively, and for the levels, Bob won't get any positive score, So his total maximum score is 4+2 = 6.

Editor Image

?