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

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. c#将Excel数据导入到数据库的实现代码(转载)

    假如Excel中的数据如下:     数据库建表如下:     其中Id为自增字段:      代码如下: using System; using System.Collections.Generic ...

  2. JQuery图片轮换 nivoSlider图片轮换

    效果图: 第一步:添加引用 <script src="jquery-ui-1.9.2.custom.min.js" type="text/javascript&qu ...

  3. java关键字 (jdk6),各自的含义是什么?

    Abstract 抽象的 一个Java语言中的关键字,用在类的声明中来指明一个类是不能被实例化的,但是可以被其它类继承.一个抽象类可以使用抽象方法,抽象方法不需要实现,但是需要在子类中被实现. bre ...

  4. DeviceToken 获取失败,原因:Error Domain=NSCocoaErrorDomain Code=3000 "未找到应用程序的“aps-environment”的授权字符串"...

    apns -> 注册推送功能时发生错误, 错误信息: Error Domain=NSCocoaErrorDomain Code=3000 "未找到应用程序的“aps-environme ...

  5. rtmpdump代码分析 转

    RTMPdump 源代码分析 1: main()函数 rtmpdump 是一个用来处理 RTMP 流媒体的工具包,支持 rtmp://, rtmpt://, rtmpe://, rtmpte://, ...

  6. 学习开发jquery插件

    先学习http://www.cnblogs.com/playerlife/archive/2012/05/11/2495269.html http://www.cnblogs.com/fromeart ...

  7. 转载:Linux的vim三种模式

    一般模式:在Linux终端中输入“vim 文件名”就进入了一般模式,但不能输入文字. 编辑模式:在一般模式下按i就会进入编辑模式,此时就可以写程式,按Esc可回到一般模式. 命令模式:在一般模式下按: ...

  8. 《javascript权威指南》读书笔记 -part2

    我真的很佩服副院长~他是一个很有耐心 极其细致的人 工作态度严谨  代码简洁风格统一~再乱遭遭的代码只要经过他的手就会变的很漂亮 羡煞我也~ 不说废话了  还是乖乖看书吧~maybe可能也许的某一天 ...

  9. python之socket编程

    本章内容 1.socket 2.IO多路复用 3.socketserver Socket socket起源于Unix,而Unix/Linux基本哲学之一就是“一切皆文件”,对于文件用[打开][读写][ ...

  10. oldboy第四天学习

    一.感觉上课没有太多的知识.也可以去理解.但是作业太难了... 二.hash() #python里面的哈希类型是在一个程序中不变,如果换了python 哈希是不#一样的. #字典为什么快,因为他把字典 ...