UVa 11292-dragon of Loowater

Source: Internet
Author: User

Title: A dragon has n. There are M-brave people. The capacity of the brave is greater than the size of the faucet can defeat him, every brave need to be able to value the equal Commission,

Ask to use at least how much money can kill the dragon.

Analysis: Greed. First of all, the Dragon and the brave fight are incremented, and then, every time you hire a brave man who can kill a dragon with the lowest current ability.

(assuming that the current brave leads to an ill-optimized solution, he had a higher commission than he had before, and he must have been hired earlier)

Description: Tian Bogey horse racing (⊙_⊙).

#include <algorithm> #include <iostream> #include <cstdlib> #include <cstdio>using namespace  Std;int d[20001];int K[20001];int Main () {int n,m;while (scanf ("%d%d", &n,&m) && n+m) {for (int i = 0; i < n;  + + i) scanf ("%d", &d[i]), for (int i = 0; i < m; + + i) scanf ("%d", &k[i]); sort (d, d+n); sort (k, k+m); int now  = 0,sum = 0,flag = 0;for (int i = 0; i < n; + + i) {while (now < M && D[i] > K[now]) now ++;if >= m) {flag = 1; break;} else sum + = K[now + +];} if (flag) printf ("Loowater is doomed!\n"), Else printf ("%d\n", sum);} return 0;}

UVa 11292-dragon of Loowater

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.