Bestcoder #47 B Senior's Gun
amp 39 47
2023-09-14 09:07:56 时间
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 carriesn guns,
and every gun has an attack power a[i] .
One day, Xuejiejie goes outside and comes acrossm monsters,
and every monster has a defensive power b[j] .
Xuejiejie can use the guni 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.
She often carries
One day, Xuejiejie goes outside and comes across
Xuejiejie can use the gun
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 integersn , m .
The second line containsn integers,
which means every gun's attack power.
The third line containsm integers,
which mean every monster's defensive power.
1≤n,m≤100000 , −109≤a[i],b[j]≤109 。
In each case:
The first line contains two integers
The second line contains
The third line contains
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 <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); } }
相关文章
- [Java Spring] Controlling API Exposure & Override Endpoint Name
- [Angular] Using the platform agnostic Renderer & ElementRef
- [Servlet&JSP] Cookie会话管理
- Parameter ' ': No size set for variable length data type: String
- 'System.Data.DataRow.DataRow(System.Data.DataRowBuilder)' is inaccessible due to its protection leve
- 华为OD机试 - 整型数组按个位值排序(Java & JS & Python)
- 华为OD机试 - 单向链表中间节点(Java & JS & Python)
- please specify user and group other than root, pool 'default'
- [BEROR]CodeSign error: code signing is required for product type 'Application' in SDK 'iOS 8.1'
- URAL 1727. Znaika's Magic Numbers(数学 vector)
- Error occured processing XML 'Cannot find class [springmvc.extention.BeanArgumentResolver]'.
- UVA - 10057 A mid-summer night's dream.
- [Android]Can't create handler inside thread that has not called Looper.prepare()
- Error creating bean with name 'memcachedClient'...java.lang.OutOfMemoryError
- 2023年网络安全自学入门:(超详细)从入门到精通学习路线&规划,学完即可就业
- 腾讯笔试题——猴子吃桃(Python&C语言实现)