zoukankan      html  css  js  c++  java
  • Bestcoder #47 B Senior's Gun

    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 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 nm.

    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,m100000109a[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

    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
    ",sum);
        }
    }
    


  • 相关阅读:
    闭包详解
    年少不知富婆好,错把少女当成宝
    var a = ? if(a==1 && a==2 && a==3){ console.log(1); }
    vue中watch监听的handler,deep,immediate用法详解
    前端VSCode常用插件-快捷键-以及常用技巧
    如何看待 Web 开发构建工具 Vite?-------------转载自知乎
    如何关联多个远程仓库
    图解 | 原来这就是网络
    QMdiArea、QMdiSubWindow
    QDockWidget
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5325826.html
Copyright © 2011-2022 走看看