Small Penalty
InterviewTime limit1sMemory limit512 MB
Pick one card from each of three players so the max minus min of the chosen numbers is as small as possible, and report that range.
- Level
Medium5 of 10
- Topics
- Sorting, Two pointers, Array
- Solved
- No attempts yet
Problem
Three people form a team and combine integers in a game. In this game, each player on each team receives one or more number cards, each with a single integer written on it. Each player chooses one of their number cards and places it on the table. Then three cards lie on the table, and the penalty is the difference between the largest and smallest of the visible numbers. This is written as follows.
| max(a,b,c) – min(a,b,c) |
Here a, b, and c are the numbers on the cards each player chose and placed.
Given the number cards dealt to the three players, write a program that finds the smallest penalty they can make.
Input
The first line gives A, the number of number cards the first player received, B, the number the second player received, and C, the number the third player received. (1 ≤ A, B, C ≤ 1,000)
The second line gives the numbers on the number cards the first player received, the third line gives the numbers on the number cards the second player received, and the fourth line gives the numbers on the number cards the third player received.
The numbers on the number cards are integers whose absolute value is less than or equal to 100,000,000.
Output
Print the smallest penalty the three players can make.