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

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
  1. /**
  2. 题意:xuejiejie有n把枪,每把枪的威慑力是mmap[i],现在有m个master,每个master
  3. 的攻击性是temp[i] ,现在xuejiejie得到的bonus值为mmap[i] - temp[i]
  4. 现在要求bonus的值最大化
  5. 做法:暴力
  6. **/
  7. #include <iostream>
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <algorithm>
  11. using namespace std;
  12. #define maxn 100000 + 10
  13. #define INF 0x7fffffff
  14. long long mmap[maxn];
  15. long long temp[maxn];
  16. int main()
  17. {
  18. //#ifndef ONLINE_JUDGE
  19. // freopen("in.txt","r",stdin);
  20. //#endif // ONLINE_JUDGE
  21. int T;
  22. scanf("%d",&T);
  23. while(T--)
  24. {
  25. int n,m;
  26. scanf("%d %d",&n,&m);
  27. for(int i=;i<n;i++)
  28. {
  29. scanf("%lld",&mmap[i]);
  30. }
  31. for(int i=;i<m;i++)
  32. {
  33. scanf("%lld",&temp[i]);
  34. }
  35. sort(mmap,mmap+n);
  36. sort(temp,temp+m);
  37. long long sum = ;
  38. long long ans = ;
  39. int p = ;
  40. for(int i=n-;i>=;i--)
  41. {
  42. if(p>=m) break;
  43. if(mmap[i] >= temp[p])
  44. {
  45. ans += mmap[i] - temp[p];
  46. sum = max(sum,ans);
  47. p++;
  48. }
  49. else
  50. {
  51. p++;
  52. i++;
  53. }
  54. }
  55. printf("%lld\n",sum);
  56. }
  57. return ;
  58. }

HDU-5281的更多相关文章

  1. hdu 5281 Senior's Gun

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5281 Senior's Gun Description Xuejiejie is a beautifu ...

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

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

  3. HDU 5281 Senior&#39;s Gun

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

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

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

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

  6. Bestcoder Round 47 && 48

    1.Senior's Array(hdu 5280) 题目大意:给出大小为N的数组和P,求将数组中的某个元素替换为P后的最大连续子段和.N<=1000 题解: 1.送分题,比赛的时候只想到枚举替 ...

  7. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  9. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  10. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

随机推荐

  1. 算法学习 拓扑排序(TopSort)

    拓扑排序 一.基本概念 在一个有向无环图(Directed Acyclic Graph, DAG)中,规定< u,v > 表示一条由u指向v的的有向边.要求对所有的节点排序,使得每一条有向 ...

  2. YBT 5.2 树形动态规划

    题解在代码中 二叉苹果树[loj 10153] /* 若要留q条边便是要留q+1个点 所以记忆化搜索 dp[pos][ans]=max(dp[pos][ans],dp[l[pos]][k]+dp[r[ ...

  3. 那些常用的JS命令

    window.location.reload()刷新当前页面. parent.location.reload()刷新父亲对象(用于框架) opener.location.reload()刷新父窗口对象 ...

  4. Wireshark中TCP segment of a reassembled PDU的含义

    By francis_hao    Sep 16,2017   在用Wireshark抓包的时候,经常会看到TCP segment of a reassembled PDU,字面意思是要重组的协议数据 ...

  5. 使用Phoenix将SQL代码移植至HBase

    1.前言 HBase是云计算环境下最重要的NOSQL数据库,提供了基于Hadoop的数据存储.索引.查询,其最大的优点就是可以通过硬件的扩展从而几乎无限的扩展其存储和检索能力.但是HBase与传统的基 ...

  6. UVA315:Network(求割点)

    Network 题目链接:https://vjudge.net/problem/UVA-315 Description: A Telephone Line Company (TLC) is estab ...

  7. How Many Nines ZOJ - 3950 打表大法好

    If we represent a date in the format YYYY-MM-DD (for example, 2017-04-09), do you know how many 9s w ...

  8. ACM1811拓扑排序和并查集

    /* ACM1811 可以利用拓扑排序和并查集解决,主要方式是利用并查集在输入数据的时候将所有相等的点合并 然后将处理完的数据统一按照一个符号方向连接成有向线段,利用的是邻接矩阵:接下来把每条边都进行 ...

  9. Generating Sets 贪心

    H - Generating Sets Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64 ...

  10. 一图看懂深度学习框架对比----Caffe Torch Theano TensorFlow

      Caffe Torch Theano TensorFlow Language C++, Python Lua Python Python Pretrained Yes ++ Yes ++ Yes ...