题目连接

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. 【LeetCode】5. Longest Palindromic Substring 最大回文子串

    题目: Given a string S, find the longest palindromic substring in S. You may assume that the maximum l ...

  2. 将Excel中数据导入数据库(三)

    上篇文章将Excel中数据导入数据库时,将从Excel读入的数据均转换成了数据库相应字段的类型,其实这是没有必要的,因为对于数据库各种类型的插入,均可以字符串格式插入.比如表WQ_SWMSAR_A字段 ...

  3. memcached学习(二)

    Slab Allocation机制:整理内存以便重复使用 最近的memcached默认情况下采用了名为Slab Allocator的机制分配.管理内存. 在该机制出现以前,内存的分配是通过对所有记录简 ...

  4. onenote网页版如何打开链接弄到客户端

    1.网页登录https://onedrive.live.com 2.登录MS帐号 3.输入复制的分享链接,回车 4.点击编辑,在客户端编辑,弹出是否启动应用,点启动,等一段时间完成.

  5. 用命令实现Win7远程桌面关机和重启

    关机 shutdown -s -t 0 重启 shutdown -r -t 0 打开运行框(Win+R键),输入上述命令即可,后面的数字表示关机/重启延迟的时间 at 12:00 shutdown - ...

  6. 在C++中调用DLL中的函数 (2)

    应用程序使用DLL可以采用两种方式: 一种是隐式链接,另一种是显式链接.在使用DLL之前首先要知道DLL中函数的结构信息. Visual C++6.0在VC\bin目录下提供了一个名为Dumpbin. ...

  7. namespace的用法

    C++中采用的是单一的全局变量命名空间.在这单一的空间中,如果有两个变量或函数的名字完全相同,就会出现冲突.当然,你也可以使用不同的名字,但有时我们并不知道另一个变量也使用完全相同的名字:有时为了程序 ...

  8. 生成ssl证书

    http://blog.csdn.net/liuchunming033/article/details/48470575 https://segmentfault.com/a/119000000256 ...

  9. Oracle笔记 六、PL/SQL简单语句块、变量定义

    1.简单SQL语句,HellWorld示例 --输出信息 begin dbms_output.put_line('Oracle Hello World!'); end; 2.变量的定义.使用 --定义 ...

  10. 在PHP应用中简化OAuth2.0身份验证集成:OAuth 2.0 Client

    在PHP应用中简化OAuth2.0身份验证集成:OAuth 2.0 Client   阅读目录 验证代码流程 Refreshing a Token Built-In Providers 这个包能够让你 ...