Problem Description
Xuejiejie is a beautiful and charming sharpshooter.
She often carries n guns, and every gun has an attack power a[i].
One day, Xuejiejie goes outside and comes across m monsters, and every monster has a defensive power b[j].
Xuejiejie can use the gun i to kill the monster j, which satisfies b[j]≤a[i], and then she will get a[i]−b[j] bonus .
Remember that every gun can be used to kill at most one monster, and obviously every monster can be killed at most once.
Xuejiejie wants to gain most of the bonus. It's no need for her to kill all monsters.
She often carries n guns, and every gun has an attack power a[i].
One day, Xuejiejie goes outside and comes across m monsters, and every monster has a defensive power b[j].
Xuejiejie can use the gun i to kill the monster j, which satisfies b[j]≤a[i], and then she will get a[i]−b[j] bonus .
Remember that every gun can be used to kill at most one monster, and obviously every monster can be killed at most once.
Xuejiejie wants to gain most of the bonus. It's no need for her to kill all monsters.
Input
In the first line there is an integer T,
indicates the number of test cases.
In each case:
The first line contains two integers n, m.
The second line contains n integers, which means every gun's attack power.
The third line contains m integers, which mean every monster's defensive power.
1≤n,m≤100000, −109≤a[i],b[j]≤109。
In each case:
The first line contains two integers n, m.
The second line contains n integers, which means every gun's attack power.
The third line contains m integers, which mean every monster's defensive power.
1≤n,m≤100000, −109≤a[i],b[j]≤109。
Output
For each test case, output one integer which means the maximum of the bonus Xuejiejie could gain.
Sample Input
1 2 2 2 3 2 2
Sample Output
1
a[i]−b[j]最大即可
AC代码:
#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
using namespace std;
typedef long long ll;
bool cmp(ll a, ll b)
{
return a > b;
}
int main(int argc, char const *argv[])
{
int t;
scanf("%d", &t);
while(t--) {
ll n, m;
scanf("%lld%lld", &n, &m);
ll a[n + 1], b[m + 1];
for(int i = 0; i < n; ++i)
scanf("%lld", &a[i]);
for(int i = 0; i < m; ++i)
scanf("%lld", &b[i]);
sort(a, a + n, cmp);
sort(b, b + m);
ll ans = 0, minx = min(n, m);
for(int i = 0; i < minx; ++i)
if(a[i] >= b[i]) ans += a[i] - b[i];
else break;
printf("%lld\n", ans);
}
return 0;
}
本文深入探讨了游戏开发领域的关键技术,包括游戏引擎、编程语言、硬件优化等,并结合人工智能与音视频处理的最新进展,展示如何将这些技术应用于游戏开发中,以提升用户体验与创新游戏玩法。
1万+

被折叠的 条评论
为什么被折叠?



