hdu 5281 Senior's Gun

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5281  

Senior's Gun

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]\leq 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\leq n, m\leq 100000$, $-10^9 \leq a[i], b[j]\leq 10^9$。

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

贪心,贪心。。

 1 #include<algorithm>
 2 #include<iostream>
 3 #include<cstdlib>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<vector>
 7 #include<map>
 8 using std::cin;
 9 using std::cout;
10 using std::endl;
11 using std::find;
12 using std::sort;
13 using std::map;
14 using std::pair;
15 using std::vector;
16 using std::multimap;
17 #define pb(e) push_back(e)
18 #define sz(c) (int)(c).size()
19 #define mp(a, b) make_pair(a, b)
20 #define all(c) (c).begin(), (c).end()
21 #define iter(c) decltype((c).begin())
22 #define cls(arr,val) memset(arr,val,sizeof(arr))
23 #define cpresent(c, e) (find(all(c), (e)) != (c).end())
24 #define rep(i, n) for (int i = 0; i < (int)(n); i++)
25 #define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
26 const int N = 100010;
27 typedef long long ll;
28 int A[N], B[N];
29 int main() {
30 #ifdef LOCAL
31     freopen("in.txt", "r", stdin);
32     freopen("out.txt", "w+", stdout);
33 #endif
34     ll ans;
35     int t, n, m, k, p;
36     scanf("%d", &t);
37     while (t--) {
38         ans = 0;
39         scanf("%d %d", &n, &m);
40         rep(i, n) scanf("%d", &A[i]);
41         rep(i, m) scanf("%d", &B[i]);
42         sort(A, A + n), sort(B, B + m);
43         k = n - 1, p = 0;
44         while (k > -1 && p < m && A[k] > B[p]) ans += A[k--] - B[p++];
45         printf("%lld\n", ans);
46     }
47     return 0;
48 }
View Code

转载于:https://www.cnblogs.com/GadyPu/p/4641694.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值