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

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 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。
 
Output
For each test case, output one integer which means the maximum of the bonus Xuejiejie could gain.
 
Sample Input
  1. 1
  2. 2 2
  3. 2 3
  4. 2 2
 
Sample Output
  1. 1
 
Source

BestCoder Round #47 ($)

  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <algorithm>
  5. #include <queue>
  6. using namespace std;
  7.  
  8. __int64 a[100005],b[100005];
  9.  
  10. int cmp(int x,int y)
  11. {
  12. return x>y;
  13. }
  14.  
  15. int main()
  16. {
  17. int t;
  18. scanf("%d",&t);
  19. while(t--)
  20. {
  21. int n,m;
  22. scanf("%d%d",&n,&m);
  23.  
  24. // memset(a,0,sizeof(a));
  25.  
  26. for(int i = 0;i < n; i++)
  27. scanf("%I64d",&a[i]);
  28. for(int i = 0;i < m; i++)
  29. scanf("%I64d",&b[i]);
  30.  
  31. sort(a,a+n,cmp);
  32. sort(b,b+m);
  33. __int64 sum = 0;
  34.  
  35. for(int i = 0;i < n; i++)
  36. {
  37. if(a[i] > b[i] &&i < m)
  38. sum += (a[i] - b[i]);
  39. //printf("%d ",a[i] - b[i]);
  40. }
  41.  
  42. printf("%I64d\n",sum);
  43. }
  44. }

Bestcoder #47 B Senior&#39;s Gun的更多相关文章

  1. HDU 5281 Senior&#39;s Gun

    Senior's Gun Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tot ...

  2. HDU 5281 Senior&#39;s Gun 杀怪

    题意:给出n把枪和m个怪.每把枪有一个攻击力,每一个怪有一个防御力.假设某把枪的攻击力不小于某个怪的防御力则能将怪秒杀,否则无法杀死.一把枪最多仅仅能杀一个怪,不能用多把枪杀同一个怪.每杀一次怪能够得 ...

  3. BestCoder #47 1001&amp;&amp;1002

    [比赛链接]cid=608">clikc here~~ ps:真是wuyu~~做了两小时.A出两道题,最后由于没加longlong所有被别人hack掉!,最后竟然不知道hack别人不成 ...

  4. HDU 5280 Senior&#39;s Array

    Senior's Array Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) T ...

  5. hdu 5282 Senior&#39;s String 两次dp

    题链:http://acm.hdu.edu.cn/showproblem.php?pid=5282 Senior's String Time Limit: 2000/1000 MS (Java/Oth ...

  6. HDU5280 Senior&#39;s Array(简单DP)

    题目链接:pid=5280">传送门 题意: 给定一个长度为n的序列,和一个改动的值p,必须从原序列中选一个位置改动成p, 求改动后的区间和的最大值. 分析: 枚举位置+最大区间和. ...

  7. BestCoder Round #75 King&#39;s Cake 模拟&amp;&amp;优化 || gcd

    King's Cake Accepts: 967 Submissions: 1572 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 6553 ...

  8. HDU 5280 Senior&#39;s Array 最大区间和

    题意:给定n个数.要求必须将当中某个数改为P,求修改后最大的区间和能够为多少. 水题.枚举每一个区间.假设该区间不改动(即改动该区间以外的数),则就为该区间和,若该区间要改动,由于必须改动,所以肯定是 ...

  9. BestCoder Round #4 Miaomiao&#39;s Geometry (暴力)

    Problem Description There are N point on X-axis . Miaomiao would like to cover them ALL by using seg ...

随机推荐

  1. html:标签原本属性

    <!doctype html>无标题文档 a标签,默认有text-decoration属性 span标签不需要清零 b标签不需要清零 em标签不需要清零 strong 相邻内嵌元素代码里面 ...

  2. (转,感谢原作者!)既然选择了Linux,有何必在乎这些——Linux wine国服LOL英雄联盟,完美运行!!

    Linux下玩国服LOL,国服哦.网络上随处都可以搜到wine美服LOL的教程,但腾讯运营的国服客户端跟美服原版相差比较大,按照美服的方式不能搞起国服LOL,由于宿舍文化,这几天我专注于wine一个国 ...

  3. Android Studio Gradle 版本不同报错解决方法

    由于GFW的原因,我们在使用as时经常出现失败,或者第一次新建工程不成功. 很多博客上已经提到了如何解决第一次新建工程Gradle构建的问题,那么在打开别的工程时依旧会报错 "Failed ...

  4. 马士兵SVN.

    下载 服务端:VisualSVN Server 和客户端:TortoiseSVN cmd,并cd 到 VisualSVN Server安装目录下的bin目录. 新建库: svnadmin create ...

  5. CodeSMART for VS.NET插件工具

    今天无聊,想起以前看过的微软的Visual Studio的插件,所以就找了找. 微软的Visual Studio本身就非常强大了,但是仍然有不足的地方,比如下面要介绍的我喜欢的代码格式化功能的这个插件 ...

  6. 解决Cacti监控图像断断续续问题

    最近cacti的图像全都是断断续续.新加的设备,图像也是这样,查看cacti 的log发现大量下面类似的错误信息:04/12/2011 03:54:37 PM - SPINE: Poller[0] H ...

  7. XP系统取消开机硬件检查

    非正常关机后进行磁盘检查,主要用于检查磁盘错误等.非法关机后会丢失一些文件或产生一些文件错误,而硬盘自检恰恰就是来检查这些错误并对之进行必要的修复,此功能如果被关闭,不能进行必要的数据恢复,久而久之会 ...

  8. XML DOM 总结一

        对这个基本概念我不介绍太多,无非就是一定格式的文本而已,我现在侧重于如何使用它.      首先看看.NET对它的支持.      首先看看这个类图:            所有的都是基于Xm ...

  9. PULL生成XML文件

    package xmlpulldemo; import java.io.FileNotFoundException; import java.io.FileOutputStream; import j ...

  10. CSS3 Transitions

    浏览器支持 属性 浏览器 transition Internet Explorer不支持过渡属性. Firefox4需要前缀-moz-. Chrome和Safari需要前缀-webkit-. Oper ...