Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5281
Study sister is a cool shooter.
She often carries n guns with her, and each gun has a damage a[i].
One day she met the M-beast, and each beast had a defensive force B[j]. Now she decided to use her gun to kill the monsters.
The elder sister can use the I gun to kill the first J monster and only when B[j]≤a[i], and she will get A[i]?b[j] score.
Each gun can be used at most once, and the beast will not revive after death. Now, my sister wants to know how many points she can get (she doesn't have to kill all the monsters).
Problem-solving ideas: The a[i] from the big to the small row order, the b[i] from small to large row order, and then a comparison on the line
#include <iostream>#include <algorithm>#include <cstdio>using namespace STD;Const intmaxn=100000+5;typedef Long LongLL; LL A[MAXN],B[MAXN];BOOLCMP (ll A, ll b) {returnA>b;}intMain () {intTscanf("%d", &t);intM,n; while(t--) {scanf("%d%d", &m,&n); for(intI=0; i<m; i++)scanf("%lld", &a[i]); Sort (a,a+m,cmp); for(intI=0; i<n; i++)scanf("%lld", &b[i]); Sort (b,b+n);//int minn=n<m?n:m; intMinn=min (M,n); LL sum=0; for(intI=0; i<minn; i++) {if(A[i]>=b[i]) sum+=a[i]-b[i];Else Break; }printf("%lld\n", sum); }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Hdu 5281 Senior ' s Gun