Ultraviolet A 11292 dragon of loowater

Source: Internet
Author: User

/*
Chinese topic warrior fight Dragon
General http://download.csdn.net/detail/lingclingc/6563601

The first n indicates the number of Dalong, and the second number M indicates the number of Dalong warriors. The next n lines indicate the size of Dalong, line M said that the attacking power of the warriors also expressed the amount of money required by the King (the ability to take more money), and asked the king to pay the least money
Solution: sort the dragon's blood volume in ascending order, and sort the attacking power of the Dragon killing warriors from small to large.
Difficulties: The bounce condition is that the dragon is killed or the number of people is insufficient.
Key Point: Sorting
Problem solving person: lingnichong
Problem solving time:
Experience in solving problems: Water Problems
*/

Dragon of loowater Crawling failedSubmit status practice ultraviolet A 11292

Description

Problem C: the dragon of loowateronce 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 always been a prime breeding ground for geese. due to the lack of predators, the geese population was out of control. the people of loowater mostly kept clear of the geese. occasionally, a goose wowould attack one of the people, and perhaps bite off a finger or two, but in general, the people tolerated 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 on his knights to slay the dragon and save the kingdom.

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 be at least as tall as the diameter of the head. the knights 'Union demands that for chopping off a head, a knight must be paid a wage equal to one gold coin for each centimetre of the knight's height."

Wocould there be enough knights to defeat the dragon? The king called on his advisors to help him decide how and which knights to hire. after having lost a lot of money building mir Park, the king wanted to minimize the expense of slaying the dragon. as one of the advisors, your job was to help the king. you took it very seriously: If you failed, you and the whole kingdom wocould be burnt to a crisp!

Input specification:

The input contains several test cases. The first line of each test case contains two integers between 1 and 20000 aggressive, indicating the numberNOf heads that the dragon has, and the numberMOf knights in the Kingdom. The nextNLines each contain an integer, and give the diameters of the Dragon's heads, in centimetres. The followingMLines each contain an integer, and specify the heights of the Knights of loowater, also in centimetres.

The last test case is followed by a line containing:

0 0
Output specification:

For each test case, output a line containing the minimum number of gold coins that the king needs to pay to slay the dragon. if it is not possible for the Knights of loowater to slay the dragon, output the line:

Loowater is doomed!
Sample input:
2 3547842 155100 0
Output for sample input:
11Loowater is doomed!
OND? EJ lhot ák


# Include <stdio. h >#include <algorithm> using namespace STD; # define maxn 20000 + 10int A [maxn], B [maxn]; int main () {int n, m; int I; while (scanf ("% d", & N, & M), N | M) {for (I = 0; I <n; I ++) scanf ("% d", & A [I]); for (I = 0; I <m; I ++) scanf ("% d ", & B [I]); sort (A, A + n); sort (B, B + M); int num = 0, cost = 0; // The ID of the header to be cut off. The total cost is for (I = 0; I <m; I ++) if (B [I]> = A [num]). {cost + = B [I]; // If (++ num = N) break for hiring the server guard; // If the header has been cut down, exit loop timely} If (Num <n) printf ("loowat Er is doomed! \ N "); elseprintf (" % d \ n ", cost) ;}return 0 ;}










Ultraviolet A 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.