题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5281

Senior's Gun

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]\leq 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\leq n, m\leq 100000$, $-10^9 \leq a[i], b[j]\leq 10^9$。

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

贪心,贪心。。

 #include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<map>
using std::cin;
using std::cout;
using std::endl;
using std::find;
using std::sort;
using std::map;
using std::pair;
using std::vector;
using std::multimap;
#define pb(e) push_back(e)
#define sz(c) (int)(c).size()
#define mp(a, b) make_pair(a, b)
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr,val) memset(arr,val,sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
const int N = ;
typedef long long ll;
int A[N], B[N];
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
ll ans;
int t, n, m, k, p;
scanf("%d", &t);
while (t--) {
ans = ;
scanf("%d %d", &n, &m);
rep(i, n) scanf("%d", &A[i]);
rep(i, m) scanf("%d", &B[i]);
sort(A, A + n), sort(B, B + m);
k = n - , p = ;
while (k > - && p < m && A[k] > B[p]) ans += A[k--] - B[p++];
printf("%lld\n", ans);
}
return ;
}

hdu 5281 Senior's Gun的更多相关文章

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

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

  2. HDU 5281 Senior&#39;s Gun

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

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

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

  4. 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: ...

  5. HDU Senior's Gun (水题)

    题意: 给n把枪,m个怪兽,每把枪可消灭1怪兽,并获得能量=枪的攻击力-怪兽的防御力.求如何射杀能获得最多能量?(不必杀光) 思路: 用最大攻击力的枪杀防御力最小的怪兽明显可获得最大能量.如果每把枪都 ...

  6. hdu 5280 Senior's Array

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

  7. 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 ...

  8. 2017多校第9场 HDU 6169 Senior PanⅡ 数论,DP,爆搜

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6169 题意:给了区间L,R,求[L,R]区间所有满足其最小质数因子为k的数的和. 解法: 我看了这篇b ...

  9. hdu 6169 Senior PanⅡ Miller_Rabin素数测试+容斥

    Senior PanⅡ Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) Pr ...

随机推荐

  1. 'UIShell.OSGi.MvcWebExtension.BundleRuntimeControllerFactory' did not return a controller for the name 'Home'.

    在使用osgi.net 框架的时候,有时会遇到这样的错误: 解决办法: 1. 检查项目文件夹下的 log 日志文件,因 osgi.net 在运行时(包括异常和操作)都会在项目的目录下生成 日志文件,并 ...

  2. 学习总结 html图片热点,网页划区,拼接,表单

    表单: action="负责处理的 <form id="" name="" method="post/get"服务端&quo ...

  3. python常用内置函数

    Python所以内置函数如下: 下面列举一些常用的内置函数: chr()和ord() chr()将数字转换为对应的ascii码表字母 >>> r=chr(65) >>&g ...

  4. 不安装Oracle客户端使用PL/SQL连接服务器端Oracle

    从10G开始,Oracle 提供了一个较为轻量级的客户包,叫做Instant Client Package. 将它安装好后,就不用再安装庞大的Oracle客户端,可以直接通过使用PL/SQL连接服务器 ...

  5. 详解android.mk-2016.01.18

    1 Android.mk作用 当使用JNI开发时,我们需要创建一个native工程,Android.mk就是一个makefile的配置文件,帮助我们把编写的C/C++代码编译成动态或者静态的链接库. ...

  6. WF4 持久化 <第四篇>

    一.基础示例 WF4 默认支持SQLServer的持续化,首先要执行目录C:\Windows\Microsoft.NET\Framework\v4.0.30319\SQL\en下的脚本: SqlPer ...

  7. 轻松找回Win7桌面“消失”的IE9图标

    打开注册表编辑器(Win+R打开运行窗口,运行regedit命令),依次展开到 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion ...

  8. BG雪碧图制作要求

    使用软件 firework 保存png-8 然后参数如下图: 格式:PNG 8 调色板:最适合 深度:128 透明度:Alpha 透明度

  9. PPTP --VPN配置

    测试:1:根据上面的步骤4,在路由器里查看状态:2:手机热点,共享给你电脑,电脑拨号,进行测试.   参考:http://jingyan.baidu.com/article/90808022ddd6a ...

  10. hdu1203

    #include <stdio.h> #include <math.h> #define mmin(x,y) (x)<(y)?(x):(y) int main(){ +] ...