Senior's Gun-------(BestCoder Round #47)
来源:互联网 发布:sql 可视化工具 编辑:程序博客网 时间:2024/05/17 01:41
Senior's Gun
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
分析:贪心。
CODE:
#include <iostream>#include <algorithm>using namespace std;int main(){ const int maxn=100005; int t,n,m; cin>>t; while(t--){ long long ans=0; cin>>n>>m; int a[maxn],b[maxn]; for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<m;i++) cin>>b[i]; sort(a,a+n); sort(b,b+m); int i=n-1,j=0; while(i>-1&&j<m){ if(a[i]>=b[j]){ ans=ans+a[i]-b[j]; i--,j++; } else break; } cout<<ans<<endl; } return 0;}
0 0
- Senior's Gun-------(BestCoder Round #47)
- HDU 5281 BestCoder Round #47 1002:Senior's Gun
- Bestcoder #47 B Senior's Gun
- HDU 5281 Senior's Gun——BestCoder Round #47(贪心)
- A、Senior's Array-------(BestCoder Round #47)
- HDU 5280 BestCoder Round #47 1001:Senior's Array
- BestCoder Round #47 ($) HDU 5280 Senior\'s Array
- hdu 5281 Senior's Gun(贪心)
- hdu 5281 Senior's Gun
- HDU 5281 Senior's Gun
- hdu 5281 Senior's Gun
- hdu-5281 Senior's Gun*
- HDU 5281 Senior's Gun
- HDU 5281 Senior's Gun
- hdu 5281 Senior's Gun(贪心)(思维)
- HDU 5281 Senior's Gun 杀怪
- HDOJ5281 Senior's Gun(贪心思想)
- HDU——5281 Senior's Gun
- CentOS yum upgrade, Error Loaded plugins: fastestmirror
- Python入门
- 华为面试:字符逆序
- Android帮助文档本地打开慢的解决方案
- HashSet练习 根据用户名密码注册账户
- Senior's Gun-------(BestCoder Round #47)
- STL源码剖析 [容器](八)[priority_queue]
- WinSCP:支持与linux互传的windows端的图形化SCP
- Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)
- iOS中属性与成员变量的区别
- 普通表向分区表转换的几种方法(转载yangtingkun blog)
- 项目整合心得
- hdu 5423 Rikka with Tree
- HDU 3397 Sequence operation(线段树区间合并)