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. 马踏棋盘问题-贪心(MATLAB&C++)

    原创文章,转载请注明:马踏棋盘问题-贪心(MATLAB&C++) By Lucio.Yang 1.问题描述 将马随机放在国际象棋的Board[0-7][0-7]的某个方格中,马按走棋规则进行移 ...

  2. 实时消息传输协议 RTMP(Real Time Messaging Protocol)

    实时消息传输协议(RTMP)最初是由 Macromedia 为互联网上 Flash player 和服务器之间传输音频.视频以及数据流而开发的一个私有协议.Adobe 收购 Macromedia 购以 ...

  3. 精通UNIX下C语言编程与项目实践

    cc  -I  //include 目录 -L //静态库目录?动态也可以 -l //小写L,接静态库名称?动态也可以 -DXXX='"XXFF"' //-D直接定义宏 -c 只编 ...

  4. ISO/IEC14443和15693的对比有何具体区别

    ISO14443 ISO14443A/B:超短距离智慧卡标准.这标准订出读取距离7-15厘米的短距离非接触智慧卡的功能及运作标准,使用的频率为13.56MHz.     ISO14443定义了TYPE ...

  5. 汇编语言学习——第二章 寄存器(CPU工作原理)

    1.一个典型的CPU由运算器.控制器.寄存器等器件组成,这些器件靠内部总线相连. 区别: 内部总线实现CPU内部各个器件之间的联系. 外部总线实现CPU和主板上其它器件的联系. 8086CPU有14个 ...

  6. ArcGIS 10 许可配置

    问题描述:在配置ArcGIS许可时,出现了许可检查通过,而无法启动arcmap的问题. 许可诊断结果如下: -------- Diagnostics -------- FLEXnet diagnost ...

  7. HDU 1711 Number Sequence KMP

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1711 AC代码: #include <iostream> #include <cs ...

  8. SharePoint迁移数据到生产环境

    SharePoint迁移数据到生产环境步骤如下: 1. 安装部署好生产环境 2. 配置管理中心 3. 安装SPD工具 4. 备份数据库(放在数据库服务器) 5. 备份wsp包(部署在管理中心服务器) ...

  9. CSS样式属性

    一.背景与前景 1.背景: 2.前景字体: (二)边界和边框 border(表格边框.样式等).margin(表外间距).padding(内容与单元格间距). margin(外边距)对自身不会有变化, ...

  10. Spring boot实现数据库读写分离

    背景 数据库配置主从之后,如何在代码层面实现读写分离? 用户自定义设置数据库路由 Spring boot提供了AbstractRoutingDataSource根据用户定义的规则选择当前的数据库,这样 ...