Senior ' s GunTime
limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 875 Accepted Submission (s): 319
Problem Descriptionxuejiejie is a beautiful and charming sharpshooter.
She often carries n Guns, and every gun have 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 < Span class= "Mrow" id= "mathjax-span-26" style= "" >b [ j " ≤ a [ i ] , and then she'll get < Span class= "Mrow" id= "mathjax-span-37" style= "" >a [ i " ? b [ ] Bonus.
Remember that every gun can is used to kill at the most one monster, and obviously every monster can is killed at the most once.
Xuejiejie wants to gain most of the bonus. It's no need for her and kill all monsters.
Inputin the first line there are an integer T , indicates the number of test cases.
In each case:
The first line contains 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 , ? ten 9 ≤a[I],b[J]≤ ten 9 。
Outputfor each test case, output one integer which means the maximum of the bonus Xuejiejie could gain.
Sample Input
12 22 32 2
Sample Output
1
Source
Bestcoder Round #47 ($)
#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);} }
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Bestcoder #47 B Senior ' s Gun