Senior's Gun

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 616    Accepted Submission(s): 241

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
 

题意:

有n把枪,m仅仅怪物。每把抢都有一个能量值。每一个怪物都有一个耗能值,如今用n把枪去打怪物,每把枪仅仅能用一次,怪物仅仅能打一次,用每i把枪打第j仅仅怪物得到能量值为a[i]-b[j],前提a[i]>=b[j],枪能够不用完,怪物也能够不打完,问最多能得多少的能量值。
解题:枚举用k把枪去打k仅仅怪物。那么每把枪都是最大能量值,每仅仅怪物都是耗能最少的。
<pre name="code" class="cpp">#include<stdio.h>
#include<algorithm>
using namespace std;
const int N = 100005;
bool cmp(int a,int b){
return a>b;
}
__int64 ans,a[N],b[N];
int main()
{ int T,n,m;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
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);
int k=0;
ans=-(1<<29);
while(k<n&&k<m){
if(k!=0){
a[k]+=a[k-1];
b[k]+=b[k-1];
}
if(ans<a[k]-b[k])
ans=a[k]-b[k];
k++;
}
printf("%I64d\n",ans);
}
}


HDU 5281 Senior&#39;s Gun的更多相关文章

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

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

  2. hdu 5281 Senior's Gun

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5281 Senior's Gun Description Xuejiejie is a beautifu ...

  3. HDU 5281 Senior's Gun (贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5281 贪心题目,但是看看我的博客里边相关贪心的题解实在是少的可怜,这里就写出来供大家一起探讨. 题意还 ...

  4. Bestcoder #47 B Senior&#39;s Gun

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

  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. HDU 5280 Senior&#39;s Array

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

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

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

  8. HDU 5281 BestCoder Round #47 1002:Senior's Gun

    Senior's Gun  Accepts: 235  Submissions: 977  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: ...

  9. hdu 5280 Senior's Array

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5280 Senior's Array Description One day, Xuejiejie ge ...

随机推荐

  1. 日常之学习CSS3变形和js函数指针

    1,transform变形属性,包括rotate(xxdeg)旋转,translate(x轴px,y轴px)移动,scale(0.5,2)变形(x轴缩小0.5倍,y轴放大2倍),skew(x轴deg, ...

  2. js兼容性大全

    js有个第二定律好的属性/选择器一定不兼容/* 获取类名通用代码*/function getClassName(){ if(document.getElementsByClassName){ doso ...

  3. 最近adt升级引起的问题

    其实也不知道是什么原因引起的,因为 之前安装的adt就是23.0.3的版本,但是最近突然创建安卓工程时出现了如下问题 D:\workspace\appcompat_v7\res\values-v21\ ...

  4. ztree树形插件

    在开发项目中需要用到树插件,近期研究了几款树插件,好记性不如烂笔头 ,写下来  以后好查 MzTreeView(梅花雪) 很经典的树形菜单脚本控件 菜单树展示加载速度快 支持1w条以上大数据 缺点-- ...

  5. Android百度地图的简单实现

    2015-06-13 最近学习了百度地图API的简单开发,现记录如下:(持续更新中) 百度地图API是为开发者免费提供的一套基于百度地图服务的应用接口,包括JavaScript API.Web服务AP ...

  6. 未能从程序集“System.ServiceModel,xxx”中加载类型“System.ServiceModel.Activation.HttpModule”。

    一.平台环境 二.问题描述 未能从程序集“System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561 ...

  7. ORACLE备份手记

    嘛的,最近一直写EPOLL的游戏服务端搞的头晕,BOSS说了要备份ORACLE,由于DBA离职了,搞这个事情搞的很蛋疼,关掉实例后备份数据库各种连接不到实例,本来今晚要完成泡泡堂游戏的DX版的,郁闷 ...

  8. [LeetCode]题解(python):108-Convert Sorted Array to Binary Search Tree

    题目来源: https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/ 题意分析: 给出一个排好序的数组,根据这 ...

  9. C语言(1)--准备

    经过很长一段时间的准备,终于重新弄懂了一些C语言的问题,再次熟悉了C语言的大致应用,对此略有体会,在此以博客记录于此! 准备工作: 运行平台:Linux 编辑工具:vim (还可以使用emac,ged ...

  10. 当x含有偶数个1,返回1,否则为0。

    题目描述: /* Return 1 when x contains an even number of 1s;0 otherwise. Assume W=32 */ int even_ones(uns ...