Under construction

Still being built. Things may change

The Dragon of Loowater

Interview

Time limit1sMemory limit128 MB

Summary
Match the smallest knight to each dragon head so that every head is cut by a tall enough knight, minimizing total height paid; report failure if impossible.
Level

Medium4 of 10

Topics
Greedy, Sorting, Two pointers, Array
Solved
No attempts yet

Problem

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 always been a prime breeding ground for geese. Due to the lack of predators, the goose population grew out of control. The people of Loowater mostly kept clear of the geese. Occasionally a goose would attack a person 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 hatched a multi-headed, fire-breathing dragon. When the dragon grew up, it threatened to burn the Kingdom of Loowater to a crisp. The king was alarmed and called on his knights to slay the dragon and save the kingdom.

The knights explained: to slay the dragon, they must chop off all of its heads. Each knight can chop off exactly one head. The heads are of different sizes. To chop off a head, a knight must be at least as tall as the diameter of that head. For chopping off a head, a knight must be paid one gold coin for each centimetre of his height.

Having already lost a fortune building Mir Park, the king wants to slay the dragon at the minimum possible total cost. As one of the king's advisors, help him decide how many and which knights to hire.

Input

The input contains several test cases.

The first line of each test case contains two integers nn and mm (1≤n,m≤200001 \le n, m \le 20000): the number of heads the dragon has and the number of knights in the kingdom. Each of the next nn lines contains one integer, the diameter of a head in centimetres. Each of the following mm lines contains one integer, the height of a knight in centimetres.

The last test case is followed by a line containing:

0 0

Output

For each test case, output a single line containing the minimum number of gold coins the king must pay to slay the dragon. If the knights of Loowater cannot slay the dragon, output the line:

Loowater is doomed!

Examples4

  1. Example 1

    Input
    2 3
    5
    4
    7
    8
    4
    2 1
    5
    5
    10
    0 0
    
    Expected output
    11
    Loowater is doomed!
    
  2. Example 2

    Input
    1 1
    5
    5
    0 0
    
    Expected output
    5
    
  3. Example 3

    Input
    1 1
    10
    5
    0 0
    
    Expected output
    Loowater is doomed!
    
  4. Example 4

    Input
    1 3
    3
    3
    10
    100
    0 0
    
    Expected output
    3