HDU Senior ' s Gun (water problem)

Source: Internet
Author: User

Test instructions: Give n guns, M monsters, each gun can destroy 1 monsters, and gain energy = Gun's attack-the monster's defense Force. How to kill to get the most energy? (No need to kill the light)

Idea: The monster with the greatest attack power will obviously get the maximum energy. If every gun is shot to kill a monster that doesn't have 1 energy, it's tantamount to throwing away all the guns.

1 //#pragma COMMENT (linker, "/stack:102400000,102400000")2#include <iostream>3#include <stdio.h>4#include <string.h>5#include <vector>6#include <stack>7#include <algorithm>8#include <map>9#include <bits/stdc++.h>Ten #defineLL Long Long One #definePII pair<int,int> A #defineINF 0x7f7f7f7f - using namespacestd; - Const intn=100000+5; the intA[n], b[n]; -  - intMain () - { +     //freopen ("Input.txt", "R", stdin); -     intt, N, M; +Cin>>T; A      while(t--) at     { -scanf"%d%d", &n, &m); -  -          for(intI=0; i<n; i++) scanf ("%d",&a[i]); -          for(intI=0; i<m; i++) scanf ("%d",&b[i]); -  inSort (A, A +n); -Sort (b, + +m); to         intbb=0, aa=n-1; +LL ans=0; -          while(aa>=0&& bb<m && a[aa]>B[BB]) the         { *ans+=a[aa]-B[BB]; $bb++;Panax Notoginsengaa--; -         } theprintf"%lld\n", ans); +     } A  the  +     return 0; -}
AC Code

HDU Senior ' s Gun (water problem)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.