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
2 2
2 3
2 2
 
Sample Output
1
 
Source

BestCoder Round #47 ($)

#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);
}
}

最新文章

  1. DevExpress.XtraGrid.view.gridview 属性说明
  2. node 异步回调解决方法之yield
  3. AD_TLC549采集模拟信号
  4. 四种常见的 POST-------- content-type数据提交方式
  5. 修改加粗cmd和powershell命令行的中文字体
  6. kaggle&amp; titanic代码
  7. Flyweight(享元)--对象结构型模式
  8. Spring 笔记
  9. SpringMVC 返回 html 视图页面,SpringMVC与Servlet,Servlet重定向与转发
  10. Java垃圾回收器
  11. [我的疑问]String? = &quot;Skiy Chan&quot; 中的问号是什么意思?
  12. 9.23 noip模拟试题
  13. Category类别
  14. HTML5 DTD
  15. Entity Framework查询原理
  16. 安装atlas后执行hive命令报错
  17. 对于ArrayList中的泛型进行分析
  18. 用VS2017进行移动开发(C#、VB.NET)——OfflineCameraButton控件,Smobiler移动开发
  19. 学号 2018-2019-20175212 实验一 《Java开发环境的熟悉》
  20. python迭代器与生成器详解

热门文章

  1. HTML中常用鼠标样式
  2. zepto源码研究 - zepto.js-4(常用的工具)
  3. 《Linux内核分析》 week2作业-时间片轮转
  4. 转发——推荐一些国外高质量Java开发者的博客
  5. php wampp 访问数据库
  6. 【回忆1314】第一次用AngularJS
  7. ADODB的应用
  8. php的header()函数前有echo输出情况分析
  9. You don&#39;t have permission to access /phpmyadmin/main.php on this server.
  10. MySQL添加中文字符集问题 --- java.sql.SQLException: Incorrect string value