Card game
Practice
3.3 (31 votes)
Algorithms
Easy
Quick sort
Problem
94% Success 16401 Attempts 20 Points 1s Time Limit 512MB Memory 1024 KB Max Code

Two friends decided to play a very exciting online card game. At the beginning of this game, each player gets a deck of cards, in which each card has some strength assigned. After that, each player picks random card from his deck and they compare strengths of picked cards. The player who picked card with larger strength wins. There is no winner in case both players picked cards with equal strength.

First friend got a deck with n cards. The i-th his card has strength \(a_i\). Second friend got a deck with m cards. The i-th his card has strength \(b_i\).

First friend wants to win very much. So he decided to improve his cards. He can increase by 1 the strength of any card for 1 dollar. Any card can be improved as many times as he wants. The second friend can't improve his cards because he doesn't know about this possibility.

What is the minimum amount of money which the first player needs to guarantee a victory for himself?

Input format

The first line of the input contains single integer n (\(1 \leq n \leq 3 \cdot 10^5\)) - the number of first friend's cards.

The second line of the input contains n space separated integers \(a_i\) (\(1 \leq a_i \leq 10^9\)) - the strength of the i-th first friend's card.

Second friend's cards are given in the next two lines in the same format.

Output format

Print single integer - the minimum amount of money which the first friend needs to guarantee a victory for himself.

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
65 votes
Tags:
ApprovedEasySorting
Points:20
11 votes
Tags:
AlgorithmsArraysBinary treeEasyHash MapsImplementationOne-dimensionalQuick SortSorting