HDU 5281 Senior's Gun

简介:

Senior's Gun

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 616    Accepted Submission(s): 241


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
 

题意:

有n把枪,m仅仅怪物。每把抢都有一个能量值。每一个怪物都有一个耗能值,如今用n把枪去打怪物,每把枪仅仅能用一次,怪物仅仅能打一次,用每i把枪打第j仅仅怪物得到能量值为a[i]-b[j],前提a[i]>=b[j],枪能够不用完,怪物也能够不打完,问最多能得多少的能量值。
解题:枚举用k把枪去打k仅仅怪物。那么每把枪都是最大能量值,每仅仅怪物都是耗能最少的。
<pre name="code" class="cpp">#include<stdio.h>
#include<algorithm>
using namespace std;
const int N = 100005;
bool cmp(int a,int b){
    return a>b;
}
__int64 ans,a[N],b[N];
int main()
{
    
    int T,n,m;
    scanf("%d",&T);
    while(T--){
        scanf("%d%d",&n,&m);
        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);
        int k=0;
        ans=-(1<<29);
        while(k<n&&k<m){
            if(k!=0){
                a[k]+=a[k-1];
                b[k]+=b[k-1];
            }
            if(ans<a[k]-b[k])
                ans=a[k]-b[k];
            k++;
        }
        printf("%I64d\n",ans);
    }
}





本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5176723.html,如需转载请自行联系原作者

相关文章
|
1月前
Strange fuction(HDU--2899)
Strange fuction(HDU--2899)
|
10月前
UVa11506 - Angry Programmer(ISAP)
UVa11506 - Angry Programmer(ISAP)
40 0
|
测试技术
HDU-1847,Good Luck in CET-4 Everybody!(巴什博弈)
HDU-1847,Good Luck in CET-4 Everybody!(巴什博弈)
POJ-2488,A Knight's Journey(DFS)
POJ-2488,A Knight's Journey(DFS)
ZOJ - Summer 2018 - Contest 1 by SBconscious - Problems - 1001: Saber
ZOJ - Summer 2018 - Contest 1 by SBconscious - Problems - 1001: Saber
73 0
|
前端开发 网络架构
HDU-1049 Climbing Worm
HDU-1049 Climbing Worm

热门文章

最新文章