HDOJ5281 Senior's Gun(贪心思想)

本文深入探讨了游戏开发领域的关键技术,包括游戏引擎、编程语言、硬件优化等,并结合人工智能与音视频处理的最新进展,展示如何将这些技术应用于游戏开发中,以提升用户体验与创新游戏玩法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.
 

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 nm.

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.

1n,m100000109a[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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值