标签:algorithm sum name def void lld pac string fine
用最牛逼的枪打最弱的怪物,先给枪和怪物排个序。
#include <iostream>
#include <queue>
#include <algorithm>
#include<cstring>
#include<cstdio>
typedef long long ll;
using namespace std;
#define MAX 100000+10
ll gun[MAX];
ll monster[MAX];
int n, m;
int main(void) {
int t;
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%lld", &gun[i]);
}
sort(gun + 1, gun + 1 + n);
reverse(gun + 1, gun + 1 + n); //STL的骚操作
for (int i = 1; i <= m; i++) {
scanf("%lld", &monster[i]);
}
ll sum = 0;
sort(monster + 1, monster + 1 + m);
if (n >= m) {
for (int i = 1; i <= m; i++) {
if (gun[i] > monster[i]) {
sum += gun[i] - monster[i];
}
else {
break;
}
}
printf("%lld\n", sum);
}
else {
for (int i = 1; i <= n; i++) {
if (gun[i] > monster[i]) {
sum += gun[i] - monster[i];
}
else {
break;
}
}
printf("%lld\n", sum);
}
}
return 0;
}
标签:algorithm sum name def void lld pac string fine
原文地址:https://www.cnblogs.com/tennant/p/8878816.html