CF1369C.RationalLee
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Lee just became Master in Codeforces, and so, he went out to buy some gifts for his friends. He bought n integers, now it's time to distribute them between his friends rationally...
Lee has n integers a1,a2,…,an in his backpack and he has k friends. Lee would like to distribute all integers in his backpack between his friends, such that the i-th friend will get exactly wi 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.
Lee 刚刚在 Codeforces 上晋升为大师,于是他出门为朋友们买了一些礼物。他买了 n 个整数,现在是时候将它们合理地分发给朋友们了……
Lee 的背包中有 n 个整数 a1,a2,…,an,他有 k 位朋友。Lee 希望将背包中的所有整数全部分发给他的朋友们,使得第 i 位朋友恰好获得 wi 个整数,且每个整数恰好分发给一位朋友。
我们定义一位朋友的“幸福值”为他所获得的所有整数中的最大值与最小值之和。
Lee 希望让朋友们尽可能幸福,即最大化所有朋友幸福值的总和。现在他请你计算这个幸福值总和的最大可能值。
输入格式
The first line contains one integer t (1≤t≤104) — the number of test cases.
Next 3t lines contain test cases — one per three lines.
The first line of each test case contains two integers n and k (1≤n≤2⋅105; 1≤k≤n) — the number of integers Lee has and the number of Lee's friends.
The second line of each test case contains n integers a1,a2,…,an (−109≤ai≤109) — the integers Lee has.
The third line contains k integers w1,w2,…,wk (1≤wi≤n; w1+w2+…+wk=n) — the number of integers Lee wants to give to each friend.
It's guaranteed that the sum of n over test cases is less than or equal to 2⋅105.
第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。
接下来的 3t 行包含测试用例,每个测试用例占三行。
每个测试用例的第一行包含两个整数 n 和 k(1≤n≤2⋅105;1≤k≤n)—— Lee 拥有的整数个数以及 Lee 的朋友人数。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(−109≤ai≤109)—— Lee 拥有的整数。
第三行包含 k 个整数 w1,w2,…,wk(1≤wi≤n;w1+w2+…+wk=n)—— Lee 想分给每位朋友的整数个数。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, print a single integer — the maximum sum of happiness Lee can achieve.
对于每个测试用例,输出一个整数——Lee 能够达到的最大幸福值之和。
输入输出样例
输入#1
3 4 2 1 13 7 17 1 3 6 2 10 10 10 10 11 11 3 3 4 4 1000000000 1000000000 1000000000 1000000000 1 1 1 1
输出#1
48 42 8000000000
说明/提示
In the first test case, Lee should give the greatest integer to the first friend (his happiness will be 17+17) and remaining integers to the second friend (his happiness will be 13+1).
In the second test case, Lee should give 10,10,11 to the first friend and to the second friend, so the total happiness will be equal to (11+10)+(11+10)
In the third test case, Lee has four friends and four integers, it doesn't matter how he distributes the integers between his friends.
在第一个测试用例中,Lee 应将最大的整数分给第一位朋友(其幸福值为 17+17),其余整数分给第二位朋友(其幸福值为 13+1)。
在第二个测试用例中,Lee 应将 {10,10,11} 分给第一位朋友,将 {11,10} 分给第二位朋友,因此总幸福值为 (11+10)+(11+10)。
在第三个测试用例中,Lee 有四位朋友和四个整数,他如何在朋友之间分配这些整数并不影响结果。
输入解题思路,AI测评打分。不知道怎么写?