A cricket tournament
Practice
2.7 (7 votes)
Quick sort
Sorting
Algorithms
Problem
67% Success 2574 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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 \(i^{th}\) match the energy level at \(i^{th}\) index is compared of both. The winner of the \(i^{th}\) match will be the one whose energy level at that index is higher.

If Bob wins in the \(i^{th}\) match, then the energy level difference (between the \(i^{th}\) 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

$$1 \le n \le 10^5$$
$$1 \le Energy\ Levels \le 10^6$$

 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
191 votes
Tags:
ApprovedEasyReadySorting
Points:20
22 votes
Tags:
ApprovedData StructuresEasyOpenSorting
Points:20
272 votes
Tags:
Binary SearchEasyOpenSorting