Card game

3.3

31 votes
Algorithms, Easy, Quick Sort
Problem

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 . Second friend got a deck with m cards. The i-th his card has strength .

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 () - the number of first friend's cards.

The second line of the input contains n space separated integers () - 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.

Time Limit: 1
Memory Limit: 512
Source Limit:
Explanation

For 6 dollars first player can improve cards from to . Second player has cards . All possible game situations:

First player always wins.

Editor Image

?