Taekwondo
InterviewTime limit1sMemory limit128 MB
Sort both weight lists and pair players to minimize the total absolute weight difference across all matches.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Sorting
- Solved
- No attempts yet
Problem
Taekwondo is a traditional Korean martial art that has grown into a modern international sport, adopted by the IOC (International Olympic Committee) as an official event of the 2000 Sydney Olympic Games. Taekwondo has both individual matches and team matches. An individual match is contested by two players, and a team match is a collection of individual matches.
You are given two groups of players and want to organize a team match. For each individual match you pick one player from the first group and one player from the second group. Every player may take part in at most one individual match, so if the two groups have sizes and , you form exactly individual matches.
For a fair contest, the two players in each individual match should have weights that are as close as possible. Given the weights of the players in both groups, find a pairing that minimizes the sum, over all individual matches, of the absolute difference between the two paired players' weights.
Input
The first line contains an integer , the number of test cases.
Each test case begins with a line containing two integers and (), the number of players in the first and second groups. The next lines each contain the weight of one player in the first group, and the following lines each contain the weight of one player in the second group. Every weight is between and and is given to one decimal place (a multiple of ). You must form pairs.
Output
For each test case, print on its own line the minimum possible sum of the absolute weight differences over the individual matches. Print the value with exactly one digit after the decimal point.