-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy path7.3.cpp
48 lines (41 loc) · 1.12 KB
/
7.3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* 题目名称:Senior's Gun
* 题目来源:HDU 5281
* 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5281
* 代码作者:杨泽邦(炉灰)
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN = 1e5 + 10;
long long gun[MAXN];
long long monster[MAXN];
bool Compare(long long x, long long y) {
return x > y;
}
int main() {
int caseNumber;
scanf("%d", &caseNumber);
while (caseNumber--) {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i) {
scanf("%lld", &gun[i]);
}
for (int i = 0; i < m; ++i) {
scanf("%lld", &monster[i]);
}
sort(gun, gun + n, Compare); //枪从大到小排序
sort(monster, monster + m); //怪从小到大排序
long long answer = 0;
for (int i = 0; i < n; ++i) {
if (i >= m || gun[i] <= monster[i]) {
break;
}
answer += (gun[i] - monster[i]);
}
printf("%lld\n", answer);
}
return 0;
}