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 ai. Second friend got a deck with m cards. The i-th his card has strength bi.
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 (1n3105) - the number of first friend's cards.
The second line of the input contains n space separated integers ai (1ai109) - 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.

Input
3
1 3 10
2
3 4
Output

4


Solution  

fi=int(input())
fec=list(map(int,input().split()))
se=int(input())
sec=list(map(int, input().split()))
ma=max(sec)+1
cost=0
for p in range(fi):
if fec[p]<ma:
cost+=(ma-fec[p])

print (cost)




if you have any problem in this code, take a screenshot and contact with Rishabh Chaubey.

Post a Comment

Previous Post Next Post