HDU-5281
Senior's Gun
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 842 Accepted Submission(s): 309
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.
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。
1
2 2
2 3
2 2
/**
题意:xuejiejie有n把枪,每把枪的威慑力是mmap[i],现在有m个master,每个master
的攻击性是temp[i] ,现在xuejiejie得到的bonus值为mmap[i] - temp[i]
现在要求bonus的值最大化
做法:暴力
**/
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define maxn 100000 + 10
#define INF 0x7fffffff
long long mmap[maxn];
long long temp[maxn];
int main()
{
//#ifndef ONLINE_JUDGE
// freopen("in.txt","r",stdin);
//#endif // ONLINE_JUDGE
int T;
scanf("%d",&T);
while(T--)
{
int n,m;
scanf("%d %d",&n,&m);
for(int i=;i<n;i++)
{
scanf("%lld",&mmap[i]);
}
for(int i=;i<m;i++)
{
scanf("%lld",&temp[i]);
}
sort(mmap,mmap+n);
sort(temp,temp+m);
long long sum = ;
long long ans = ;
int p = ;
for(int i=n-;i>=;i--)
{
if(p>=m) break;
if(mmap[i] >= temp[p])
{
ans += mmap[i] - temp[p];
sum = max(sum,ans);
p++;
}
else
{
p++;
i++;
}
}
printf("%lld\n",sum);
}
return ;
}
HDU-5281的更多相关文章
- hdu 5281 Senior's Gun
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5281 Senior's Gun Description Xuejiejie is a beautifu ...
- HDU 5281 Senior's Gun (贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5281 贪心题目,但是看看我的博客里边相关贪心的题解实在是少的可怜,这里就写出来供大家一起探讨. 题意还 ...
- HDU 5281 Senior's Gun
Senior's Gun Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tot ...
- HDU 5281 Senior's Gun 杀怪
题意:给出n把枪和m个怪.每把枪有一个攻击力,每一个怪有一个防御力.假设某把枪的攻击力不小于某个怪的防御力则能将怪秒杀,否则无法杀死.一把枪最多仅仅能杀一个怪,不能用多把枪杀同一个怪.每杀一次怪能够得 ...
- 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: ...
- Bestcoder Round 47 && 48
1.Senior's Array(hdu 5280) 题目大意:给出大小为N的数组和P,求将数组中的某个元素替换为P后的最大连续子段和.N<=1000 题解: 1.送分题,比赛的时候只想到枚举替 ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- 专题训练之2-sat
推荐几篇博客:https://blog.csdn.net/JarjingX/article/details/8521690 研究总结2-sat问题 https://blog.csdn.net/wher ...
- STL之四:list用法详解
转载于:http://blog.csdn.net/longshengguoji/article/details/8520891 list容器介绍 相对于vector容器的连续线性空间,list是一个双 ...
- D-query SPOJ - DQUERY(莫队)统计不同数的数量
Given a sequence of n numbers a1, a2, ..., an and a number of d-queries. A d-query is a pair (i, j) ...
- was(websphere application server)中用apache的httpclient时jar包冲突问题的解决
这个问题可以用was的共享库解决. 具体解决方案如下图所示: 对于有多个jar包冲突时,为每个冲突的jar包都新建一个共享库即可. 我之前的错误操作是以为一个共享库可以添加多个冲突的jar包用分号和逗 ...
- bzoj 2599 [IOI2011]Race 点分
[IOI2011]Race Time Limit: 70 Sec Memory Limit: 128 MBSubmit: 4768 Solved: 1393[Submit][Status][Dis ...
- android Handler post sendMessage
Handler 为Android操作系统中的线程通信工具,包为android.os.Handler. 与Handler绑定的有两个队列,一个为消息队列,另一个为线程队列.Handler可以通过这两个队 ...
- zk-web
Ref:https://github.com/qiuxiafei/zk-web zk-web是一个用clojure with noir and boostrap写的Zookeeper WEB UI管理 ...
- asp.net 权限管理系统
asp.net webform ,基于组织机构.角色的权限管理系统. 网上找的,挺好.随拿来分享. https://bitbucket.org/zzhi/asp.net
- js数组的误解
js数组实际是个残废货,没有关联数组这一说,要实现真正意义上的关联数组只能用对象,那你肯定不服气了,说怎么没有关联数组,我来给你写一个: var arr = []; arr['a'] = 1; arr ...
- 【GDKOI2016Day1T1-魔卡少女】【拆位】线段树维护区间内所有连续子区间的异或和
题意:给出N个数,M个操作.操作有修改和询问两种,每次修改将一个数改成另一个数,每次询问一个区间的所有连续子区间的异或和.n,m<=100000,ai<=1000 题解: 当年(其实也就是 ...