Uva11292--------------(The Dragon of Loowater) Dragon Quest (greedy after sorting)

Source: Internet
Author: User
Tags chop

---restore content starts---

Topic:

Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem.

The shores of Rellau Creek in central Loowater had all been a prime breeding ground for geese. Due to the lack of predators, the geese population is out of control. The people of Loowater mostly kept clear of the geese. Occasionally, a goose would attack one of the people, and perhaps bite off a finger or both, but in general, the people Tol Erated the geese as a minor nuisance.

One day, a freak mutation occurred, and one of the geese spawned a multi-headed fire-breathing dragon. When the dragon grew up, he threatened to burn the kingdom of Loowater to a crisp. Loowater had a major problem. The king was alarmed, and called in his knights to slay the Dragon and save.

The Knights explained: "To slay the dragon, we must chop off all its heads. Each knight can chop off one of the Dragon ' s heads. The heads of the dragon are of different sizes. In order to chop off a head, a knight must is at least as tall as the diameter of the head. The Knights ' union demands that for chopping off a head, a knight must is paid a wage equal to one gold coin for each cent Imetre of the Knight ' s height. "

Would there is enough knights to defeat the dragon? The king called on he advisors to help him decide how many and which knights to hire. After has lost a lot of money building Mir Park, the king wanted to minimize the expense of slaying. As one of the advisors, your job is to help the king. You took it very seriously:if your failed, you and the whole kingdom would is burnt to a crisp!

Input

The input contains several test cases. The first line of all test case contains integers between 1 and 20000 inclusive, indicating the number n of Heads that the dragon have, and the number m of knights in the kingdom. The next nlines each contain a integer, and give the diameters of the Dragon ' s heads, in centimetres. The following mlines each contain a integer, and specify the heights of the Knights of Loowater, also in centime Tres.

The last test case was followed by a line containing:

0 0

Output

For each test case, output a line containing the minimum number of gold coins that the king needs to pay to slay the Drago N. If It is not a possible for the Knights of Loowater to slay the dragon, output the line:

Loowater is doomed!


This type of question is actually a very basic problem, we know that every knight has its own commission, and the more Commission on behalf of the Knight's ability, the larger the diameter of the head of the dragon can be chopped, so we should try to ensure that the ability of the knight to kill the dragon relatively big head, and the ability of the average knight to kill a smaller relative diameter of the head, so we need to the evil faucet diameter and knight's ability from large to small sort, then greedy on OK ~!

#include <iostream>#include<algorithm>#include<stdio.h>using namespacestd;#defineMAX 20005intA[max];intB[max];intMain () {intN, M;  while(cin>>n>>L) {        if(n = =0&& m = =0)             Break;  for(inti =0; I < n; i++) Cin>>A[i];  for(intj =0; J < M; J + +) Cin>>B[j]; Sort (A,a+N); Sort (b,b+m); intCur =0 ; intCost =0 ;  for(inti =0; I < m; i++ ){            if(B[i] >=A[cur]) { Cost+=B[i]; Cur++; if(cur = =N) Break; }        }        if(Cur <N) printf ("Loowater is doomed!\n"); Elseprintf ("%d\n", cost); }    return 0;}

Uva11292--------------(The Dragon of Loowater) Dragon Quest (greedy after sorting)

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.