博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Bestcoder #47 B Senior's Gun
阅读量:6321 次
发布时间:2019-06-22

本文共 1941 字,大约阅读时间需要 6 分钟。

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


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.
1n,m100000
109a[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

#include 
#include
#include
#include
#include
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); }}

转载地址:http://sdvaa.baihongyu.com/

你可能感兴趣的文章
转:58到家数据库30条军规解读
查看>>
石家庄地铁售票系统源码及截图(结对作业)
查看>>
c#线程参考
查看>>
iOS App上架流程(2016详细版)
查看>>
html
查看>>
123
查看>>
WP8.1 Study4:WP8.1中控件集合应用
查看>>
026-请问你怎么测试网络协议
查看>>
using 的三种用法
查看>>
WinForm 曲线图控件
查看>>
C语言博客作业--函数嵌套调用
查看>>
Professional WCF 4读书笔记(2)——消息交换模式
查看>>
AlwaysOn 部分笔记及文档连接
查看>>
【硬件】运放的那些事儿
查看>>
Java内存回收机制基础[转]
查看>>
js 数据类型和转化
查看>>
Web API With AJAX: Handle Session in Web API
查看>>
Javascript 的addEventListener()及attachEvent()区别分析
查看>>
sicily 1259 Sum of Consecutive Primes
查看>>
Houdini Krakatoa Render Plugin
查看>>