HDOJ5281 Senior's Gun(贪心思想)
来源:互联网 发布:服务器数据库恢复 编辑:程序博客网 时间:2024/05/17 06:53
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
12 22 32 2
Sample Output
1
a[i]−b[j]最大即可
AC代码:
#include "iostream"#include "cstdio"#include "cstring"#include "algorithm"using namespace std;typedef long long ll;bool cmp(ll a, ll b){return a > b;}int main(int argc, char const *argv[]){int t;scanf("%d", &t);while(t--) {ll n, m;scanf("%lld%lld", &n, &m);ll a[n + 1], b[m + 1];for(int i = 0; i < n; ++i)scanf("%lld", &a[i]);for(int i = 0; i < m; ++i)scanf("%lld", &b[i]);sort(a, a + n, cmp);sort(b, b + m);ll ans = 0, minx = min(n, m);for(int i = 0; i < minx; ++i)if(a[i] >= b[i]) ans += a[i] - b[i];else break;printf("%lld\n", ans);}return 0;}
1 0
- HDOJ5281 Senior's Gun(贪心思想)
- hdu 5281 Senior's Gun(贪心)
- HDU 5281 Senior's Gun 贪心
- hdu 5281 Senior's Gun(贪心)(思维)
- hdu 5281 Senior's Gun
- HDU 5281 Senior's Gun
- hdu 5281 Senior's Gun
- hdu-5281 Senior's Gun*
- HDU 5281 Senior's Gun
- HDU 5281 Senior's Gun
- HDU 5281 Senior's Gun——BestCoder Round #47(贪心)
- HDU 5281 Senior's Gun 杀怪
- Bestcoder #47 B Senior's Gun
- Senior's Gun-------(BestCoder Round #47)
- HDU——5281 Senior's Gun
- HDU 5281 BestCoder Round #47 1002:Senior's Gun
- HDU 5280 Senior's Array(DP思想 暴力)
- HDU 5280 Senior's Array
- 最大连续字数列和的问题
- Cocos2D游戏之旅(二):主角血条的实现
- c#初始化顺序
- HDU 1452 Happy 2004
- UITableView
- HDOJ5281 Senior's Gun(贪心思想)
- 循环多少次(HDU 1799)
- shell小技巧--用“$$”和"$0"防止同一个脚本启动多次
- 【NOIP2014】飞扬的小鸟题解
- extern static
- Adaptive Thresholding Using the Integral Image ( Derek Bradley* Gerhard Roth)
- SSH学习九 依赖注入及加载Spring配置文件的方法
- netty开发教程(一)
- cocos2d-x学习日记 - 3. 坐标系