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. HTML标签练习

    <html> <> <body> <h4>一个无序列表:</h4> <ul> <li><a href=&quo ...

  2. hdu 2190

    //hdu2190 水题  题意是给一个n*3的教室,用1*1,2*2的砖去铺满,有多少种铺法,一开始没发现这个规律,想了一下,应该是递归. #include <iostream> usi ...

  3. 汇编笔记之 ret 、retf和call

    作用: ret  将 栈顶数据出栈到IP retf 将 栈顶数据出栈到IP ,然后再次将栈顶数据出栈到CS 这样一来,可以使程序跳转到已经定义好了的代码段去执行. call 语法 call s0 (如 ...

  4. javascript 广告移动特效

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  5. print流

    PrintWriter和PrintStream都属于输出流,分别针对字符和字节. PrintWriter和PrintStream提供了重载的print,println方法用于多种类型的输出 Print ...

  6. js中apply和call的用法 以及apply的妙用 (来自网络)

    apply:方法能劫持另外一个对象的方法,继承另外一个对象的属性. Function.apply(obj,args)方法能接收两个参数obj:这个对象将代替Function类里this对象args:数 ...

  7. 外国高手画神级的linux 内核图,够详细!

  8. Oracle错误问题---- 《ora-12638:身份证明检索失败》

    使用客户端可以连接,但只有一个站点出现此问题,非常郁闷,网上查了一下,发现是用户认证问题,解决办法如下: 在ORACLE客户端目录下 NETWORK/ADMIN下的sqlnet.ora,使用记事本打开 ...

  9. js插件zClip实现复制到剪贴板功能

    相信这个功能大家平时上网经常能碰到,以前也没怎么留意怎么实现的,直到项目中需要. 网上一搜一大堆,单纯使用js方法也不是没有,但是由于各浏览器的安全机制不同,不是跨浏览器的.去看了几个常用的网站,都是 ...

  10. 用C实现一个简单的对拍器——致每个曾经为求AC披星戴月的程序员们

    大一新生,首次创作,虚心受教. 实现思路: 一.需要一个输入文件(input.txt),两个对拍程序(main1.exe,main2.exe) 二.将标准输入重定向为input.txt.将标准输出分别 ...