UVa 11292 Dragon of Loowater (water problem, sort)

Source: Internet
Author: User

Test instructions: There are n Dragon, in the mercenary warrior to kill, each warrior ability value is X, can only kill the head of the diameter y is less than or equal to their ability value of the dragon, can only be hired once, and you have to give X bounty, the least reward.

Analysis: Very simple, it is obvious that the ability to kill a large diameter, low kill diameter small. So we first order the warrior ability from small to large, and then the diameter of the dragon from small to large sort,

And then sweep once, such as a warrior killed the dragon, you can skip, sweep to the end, if the killing is over, the output costs, otherwise is not killed.

The code is as follows:

#include <iostream> #include <cstdio> #include <climits> #include <cmath> #include < algorithm> #include <cstring> #include <map>using namespace std;const int maxn = 20000 + 10;int A[MAXN], B[ma Xn];int Main () {    int n, m;    while (scanf ("%d%d", &n, &m) && m && N) {        for (int i = 0; i < n; ++i)    scanf ("%d", &a[ I]);        for (int i = 0; i < m; ++i)    scanf ("%d", &b[i]);        Sort (A, a+n);  Sort (b, b+m);        if (n > m) {  printf ("Loowater is doomed!\n");  Continue;   } Warriors too little, directly ending        int cnt = 0, cost = 0;        for (int i = 0; l < m; ++i)            if (B[i] >= a[cnt]) {                Cost + = b[i];//Write down charges                if (++cnt = = N)  break;//the Dragon is dead, Tim. Before exiting            }        if (CNT < n)  printf ("Loowater is doomed!\n");        else printf ("%d\n", cost);    }    return 0;}

UVa 11292 Dragon of Loowater (water problem, sort)

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.