Bestcoder #47 B Senior's Gun
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
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.
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。
1
2 2
2 3
2 2
1
#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's Gun的更多相关文章
- 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个怪.每把枪有一个攻击力,每一个怪有一个防御力.假设某把枪的攻击力不小于某个怪的防御力则能将怪秒杀,否则无法杀死.一把枪最多仅仅能杀一个怪,不能用多把枪杀同一个怪.每杀一次怪能够得 ...
- BestCoder #47 1001&&1002
[比赛链接]cid=608">clikc here~~ ps:真是wuyu~~做了两小时.A出两道题,最后由于没加longlong所有被别人hack掉!,最后竟然不知道hack别人不成 ...
- HDU 5280 Senior's Array
Senior's Array Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) T ...
- hdu 5282 Senior's String 两次dp
题链:http://acm.hdu.edu.cn/showproblem.php?pid=5282 Senior's String Time Limit: 2000/1000 MS (Java/Oth ...
- HDU5280 Senior's Array(简单DP)
题目链接:pid=5280">传送门 题意: 给定一个长度为n的序列,和一个改动的值p,必须从原序列中选一个位置改动成p, 求改动后的区间和的最大值. 分析: 枚举位置+最大区间和. ...
- BestCoder Round #75 King's Cake 模拟&&优化 || gcd
King's Cake Accepts: 967 Submissions: 1572 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 6553 ...
- HDU 5280 Senior's Array 最大区间和
题意:给定n个数.要求必须将当中某个数改为P,求修改后最大的区间和能够为多少. 水题.枚举每一个区间.假设该区间不改动(即改动该区间以外的数),则就为该区间和,若该区间要改动,由于必须改动,所以肯定是 ...
- BestCoder Round #4 Miaomiao's Geometry (暴力)
Problem Description There are N point on X-axis . Miaomiao would like to cover them ALL by using seg ...
随机推荐
- Cannot modify header information - headers already sent by
有时候你在使用 header("Location: http://localhost/myblog/index.php/manager/listview");的时候会出现这个问题, ...
- redis入门指南学习笔记
redis的常见命令 set key hello get key incr num get num set foo lorem incr foo hset car price 500 hset car ...
- maven项目java包名的路径问题
maven项目中错误: 找不到或无法加载主类
- 数据库、C#、Java生成唯一GUID 方法
GUID(Global unique identifier)全局唯一标识符,它是由网卡上的标识数字(每个网卡都有唯一的标识号)以及 CPU 时钟的唯一数字生成的的一个 16 字节的二进制值.GUID ...
- 原生js 学习之array 数组
Array的原生方法: concat(): 连接两个或更多的数组哦 join(): 把数组的所有元素放在一个字符串中 pop():删除并返回数组的最后一个元素 push():向数组的末尾添加一个元素 ...
- SVN库迁移整理方法总结
有时候需要从一台机器迁移svn存储库到另外一台机器,如果数据量非常大的话,没有好的方法是很不方便的,其实迁移svn跟迁移mysql差不多,也有导出导入的方案 以下是subversion官方推荐的备份方 ...
- 认识html标签
让我们通过一个网页的学习,来对html标签有一个初步理解. 平常大家说的上网就是浏览各种各式各样的网页,这些网页都是由html标签组成的. 下面就是一个简单的网页.效果图如下: 我们来分析一下,这个网 ...
- Qt5-控件-QRadioButton-单选按钮-用于从多个选项中选取一个-单选神器
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QRadioButton> ...
- QT学习篇: 入门(二)
库存订单界面: (1)包括序号.订单代码.订单名称.产品代码.产品类型.计划加工数量.最晚完工日期. (2)model增加临时map,用于存储库存订单. (3)后台计算完成后,会将库存订单推送给前台, ...
- 关于常用却忘记的css,jQuery
text-indent:35px;//首行缩进 line-height:12px;//行高,高度和外层高度一样就会居中 box-shadow:inset 0px 0px 2px #ccc; conte ...