欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1921D.Very Different Array
Very Different Array
Petya has an array of integers. His brother Vasya became envious and decided to make his own array of integers.
To do this, he found integers (), and now he wants to choose some integers of them and arrange them in a certain order to obtain an array of length .
To avoid being similar to his brother, Vasya wants to make his array as different as possible from Petya's array. Specifically, he wants the total difference to be as large as possible.
Help Vasya find the maximum difference he can obtain.
Input
Each test consists of multiple test cases. The first line contains a single integer () — the number of test cases. This is followed by a description of the test cases.
The first line of each test case contains two integers and ().
The second line of each test case contains integers (). The third line of each test case contains integers ().
It is guaranteed that in a test, the sum of over all test cases does not exceed .
Output
For each test case, output a single integer — the maximum total difference that can be obtained.
Note
In the first example, Vasya can, for example, create the array . Then the total difference will be .
In the second example, all the integers available to Vasya are equal to 1, so he can only create the array , for which the difference .
In the third example, Vasya can, for example, create the array . Then the total difference will be .
Samples
9
4 6
6 1 2 4
3 5 1 7 2 3
3 4
1 1 1
1 1 1 1
5 5
1 2 3 4 5
1 2 3 4 5
2 6
5 8
8 7 5 8 2 10
2 2
4 1
9 6
4 6
8 10 6 4
3 10 6 1 8 9
3 5
6 5 2
1 7 9 7 2
5 5
9 10 6 3 7
5 9 2 3 9
1 6
3
2 7 10 1 1 5
16
0
12
11
10
23
15
25
7
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |