HDU 5281 Senior ' s Gun

Source: Internet
Author: User

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

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.