This page is still under construction.

Parts of this page are still being built. What you see may change.

Taekwondo

Interview

Time limit1sMemory limit128 MB

Summary
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 n1n_1 and n2n_2, you form exactly min⁡{n1,n2}\min\{n_1, n_2\} 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 TT, the number of test cases.

Each test case begins with a line containing two integers n1n_1 and n2n_2 (1≤n1,n2≤5001 \le n_1, n_2 \le 500), the number of players in the first and second groups. The next n1n_1 lines each contain the weight of one player in the first group, and the following n2n_2 lines each contain the weight of one player in the second group. Every weight is between 40.040.0 and 130.0130.0 and is given to one decimal place (a multiple of 0.10.1). You must form min⁡{n1,n2}\min\{n_1, n_2\} pairs.

Output

For each test case, print on its own line the minimum possible sum of the absolute weight differences over the min⁡{n1,n2}\min\{n_1, n_2\} individual matches. Print the value with exactly one digit after the decimal point.

Examples1

  1. Example 1

    Input
    2
    2 3
    44.9
    50.0
    77.2
    86.4
    59.8
    4 2
    44.9
    50.0
    77.2
    86.4
    59.8
    58.9
    
    Expected output
    42.1
    23.8