Problem Description Xuejiejie is a beautiful and charming sharpshooter. 他想获得最高的赏金。不需要击杀全部怪兽 Input In the first line there is an integer T , indicates the number of test cases.
Output For each test case, output one integer which means the maximum of the bonus Xuejiejie could gain.
Sample Input
Sample Output 1
|
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long hp[100001];
long long ad[100001];
bool compare(long long& a,long long& b) {
return a > b;
}
int main() {
int caseNum;
cin >> caseNum;
for (int caseNo = 1; caseNo <= caseNum; caseNo++) {
int n , m; // n个ad // m个hp
cin >> n >> m;
for (int i = 0; i <= n - 1; i++) {
scanf("%lld",&ad[i]);
}
for (int i = 0; i <= m - 1; i++) {
scanf("%lld",&hp[i]);
}
sort(ad, ad + n, compare); // 伤害从大到小
sort(hp, hp + m); // hp从小到大
long long sum = 0;
int no = 0;
for (int i = 0; i <= n - 1; i ++) {
if (ad[i] >= hp[i] && i <= m - 1) {
sum += ad[i] - hp[i];
} else {
break;
}
}
cout << sum << endl;
}
}