Bestcoder #47 B Senior's Gun
Senior's Gun
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 875 Accepted Submission(s): 319
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.
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。
1
2 2
2 3
2 2
1
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
using namespace std; __int64 a[100005],b[100005]; int cmp(int x,int y)
{
return x>y;
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d%d",&n,&m); // memset(a,0,sizeof(a)); for(int i = 0;i < n; i++)
scanf("%I64d",&a[i]);
for(int i = 0;i < m; i++)
scanf("%I64d",&b[i]); sort(a,a+n,cmp);
sort(b,b+m);
__int64 sum = 0; for(int i = 0;i < n; i++)
{
if(a[i] > b[i] &&i < m)
sum += (a[i] - b[i]);
//printf("%d ",a[i] - b[i]);
} printf("%I64d\n",sum);
}
}
Bestcoder #47 B Senior's Gun的更多相关文章
- HDU 5281 Senior's Gun
Senior's Gun Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tot ...
- HDU 5281 Senior's Gun 杀怪
题意:给出n把枪和m个怪.每把枪有一个攻击力,每一个怪有一个防御力.假设某把枪的攻击力不小于某个怪的防御力则能将怪秒杀,否则无法杀死.一把枪最多仅仅能杀一个怪,不能用多把枪杀同一个怪.每杀一次怪能够得 ...
- BestCoder #47 1001&&1002
[比赛链接]cid=608">clikc here~~ ps:真是wuyu~~做了两小时.A出两道题,最后由于没加longlong所有被别人hack掉!,最后竟然不知道hack别人不成 ...
- HDU 5280 Senior's Array
Senior's Array Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) T ...
- hdu 5282 Senior's String 两次dp
题链:http://acm.hdu.edu.cn/showproblem.php?pid=5282 Senior's String Time Limit: 2000/1000 MS (Java/Oth ...
- HDU5280 Senior's Array(简单DP)
题目链接:pid=5280">传送门 题意: 给定一个长度为n的序列,和一个改动的值p,必须从原序列中选一个位置改动成p, 求改动后的区间和的最大值. 分析: 枚举位置+最大区间和. ...
- BestCoder Round #75 King's Cake 模拟&&优化 || gcd
King's Cake Accepts: 967 Submissions: 1572 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 6553 ...
- HDU 5280 Senior's Array 最大区间和
题意:给定n个数.要求必须将当中某个数改为P,求修改后最大的区间和能够为多少. 水题.枚举每一个区间.假设该区间不改动(即改动该区间以外的数),则就为该区间和,若该区间要改动,由于必须改动,所以肯定是 ...
- BestCoder Round #4 Miaomiao's Geometry (暴力)
Problem Description There are N point on X-axis . Miaomiao would like to cover them ALL by using seg ...
随机推荐
- 启动android程序报错
提示错误如下: The connection to adb is down, and a severe error has occured. [2010-03-11 09:36:56 - HelloO ...
- (转)XML CDATA是什么?
解析数据 XML 解析器通常情况下会处理XML文档中的所有文本. 当XML元素被解析的时候,XML元素内部的文本也会被解析: <message>This text is also pars ...
- C# - Excel - Microsoft Access 数据库引擎找不到对象
我几乎要无语了,疯掉了,以为是office本身的问题,换了好多次office2007,安装又不顺利,换到了office2010,想想大部分应该兼容2007,所以用着office2010了. 甚至差点要 ...
- osg for android (一) 简单几何物体的加载与显示
1. 首先需要一个OSG for android的环境. (1).NDK 现在Eclipse 对NDK已经相当友好了,已经不需要另外cygwin的参与,具体可以参考 Android NDK开发篇(一) ...
- GitHub——如何更新已经fork的代码
github上有个很方便的功能叫fork,将别人的工程一键复制到自己账号下.这个功能很方便,但有点不足的是,当源项目更新后,你fork的分支并不会一起更新,需要自己手动去更新.下面记录下网上找到的更新 ...
- 制作PHP安装程序的原理和步骤56
制作PHP安装程序的原理和步骤56 1.制作PHP安装程序的原理和步骤检查目录或文件的权限----修改或填加配置文件---检查配置文件正 确性---导入数据库----锁定或删除安装文件 原理: 其实P ...
- 如何使用service命令来管理nginx
如何使用service命令来管理nginx??? 如: service nginx start service nginx restart service nginx stop service ngi ...
- win64安装及配置apache+php+mysql
Windows是64位Win7,所以Apache.PHP和Mysql都选用的64位版本(最好是统一64位). Apache:httpd-2.4.7-win64.zip PHP:PHP-5.4.6-Wi ...
- JSP与Servlet之间传值
Jsp与Servlet之间的传值有两种,一种是Jsp传值给Sevlet,另一种是Servlet传值给Jsp:使用request.response对象完成传值,具体实现如下: 1.JSP传值给Servl ...
- SQLiteDatabase里面的简单操作数据库的方法
1.使用insert方法插入记录SQLiteDatabase的insert方法的签名为long insert(String table,String nullColumnHack,ContentVal ...