Bestcoders
来源:互联网 发布:淘宝上的耐克是真的吗 编辑:程序博客网 时间:2024/06/08 14:52
Senior's Gun
Accepts: 235
Submissions: 977
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
问题描述
学姐姐是一个酷酷的枪手。她常常会随身携带n 把枪,每把枪有一个攻击力a[i] 。有一天她遇到了m 只怪兽,每只怪兽有一个防御力b[j] 。现在她决定用手中的枪消灭这些怪兽。学姐姐可以用第i 把枪消灭第j 只怪兽当且仅当b[j]≤a[i] ,同时她会获得a[i]−b[j] 的分数。每把枪至多只能使用一次,怪兽死后也不会复活。现在学姐姐想知道她最多能得到多少分(她可以不用消灭所有的怪兽)。
输入描述
第一行包含一个整数T ,表示测试数据组数。对于每组测试数据:第一行包含两个整数n,m ,表示枪的数量和怪兽的数量。第二行包含n 个整数a[i] ,表示枪的攻击力。第三行包含m 个整数b[j] ,表示怪兽的防御力。1≤n,m≤100000 ,−109≤a[i],b[j]≤109 。
输出描述
对于每组测试数据,输出一个整数表示对应的答案。
输入样例
12 22 32 2
输出样例
1
#include <iostream>#include <cstdio>#include <algorithm>using namespace std;#define maxn 100000 + 10int a[maxn], b[maxn];int T, n, m;bool cmp(int a1, int a2){ return a1 > a2;}int main(){ cin>>T; while(T--) { scanf("%d%d", &n, &m); for(int i=0; i<n; i++) scanf("%d", &a[i]); for(int i=0; i<m; i++) scanf("%d", &b[i]); sort(a, a+n, cmp); sort(b, b+m); long long ans = 0; for(int i=0; i<n; i++) { if(a[i]>=b[i] && i<m) ans += (a[i] - b[i]); else break; } printf("%I64d\n", ans); } return 0;}/*14 31 2 3 43 3 34 41 2 3 40 1 2 34 3 2 10 1 2 3*/
0 0
- bestcoders
- Bestcoders
- Bestcoders
- BestCoders
- Bestcoders
- Bestcoders
- bestcoders Happy Birthday
- bestcoders pog love szhIII
- Bestcoders 51 div2 1001
- Bestcoders 57 1002
- Bestcoders 回文串 Manacher 算法
- Bestcoders 56 Clarke and puzzle
- Bestcoders 56 Clarke and problem
- linux下uart应用编程
- AFN的使用
- Unity 自动寻路Navmesh之高级主题
- Php基础文件操作
- hdu 1171 Big Event in HDU
- Bestcoders
- CM3 STM32F的低功耗
- jQuery插件开发的五种形态小结
- Unity 自动寻路Navmesh之跳跃,攀爬,斜坡
- 画图解释 SQL join 语句
- usb mtp激活流程
- iOS 使用Quartz 2D画虚线
- 敏捷开发之道
- [Elasticsearch] 部分匹配 (一) - 前缀查询