#P1369C. RationalLee
RationalLee
No submission language available for this problem.
Description
Lee just became Master in Codeforces, and so, he went out to buy some gifts for his friends. He bought integers, now it's time to distribute them between his friends rationally...
Lee has integers in his backpack and he has friends. Lee would like to distribute all integers in his backpack between his friends, such that the -th friend will get exactly integers and each integer will be handed over to exactly one friend.
Let's define the happiness of a friend as the sum of the maximum and the minimum integer he'll get.
Lee would like to make his friends as happy as possible, in other words, he'd like to maximize the sum of friends' happiness. Now he asks you to calculate the maximum sum of friends' happiness.
The first line contains one integer () — the number of test cases.
Next lines contain test cases — one per three lines.
The first line of each test case contains two integers and (; ) — the number of integers Lee has and the number of Lee's friends.
The second line of each test case contains integers () — the integers Lee has.
The third line contains integers (; ) — the number of integers Lee wants to give to each friend.
It's guaranteed that the sum of over test cases is less than or equal to .
For each test case, print a single integer — the maximum sum of happiness Lee can achieve.
Input
The first line contains one integer () — the number of test cases.
Next lines contain test cases — one per three lines.
The first line of each test case contains two integers and (; ) — the number of integers Lee has and the number of Lee's friends.
The second line of each test case contains integers () — the integers Lee has.
The third line contains integers (; ) — the number of integers Lee wants to give to each friend.
It's guaranteed that the sum of over test cases is less than or equal to .
Output
For each test case, print a single integer — the maximum sum of happiness Lee can achieve.
Samples
Note
In the first test case, Lee should give the greatest integer to the first friend (his happiness will be ) and remaining integers to the second friend (his happiness will be ).
In the second test case, Lee should give to the first friend and to the second friend, so the total happiness will be equal to
In the third test case, Lee has four friends and four integers, it doesn't matter how he distributes the integers between his friends.