UVa 11292 - Dragon of Loowater

11292 - Dragon of Loowater

 * http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=24&problem=2267
 * http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=24&problem=2267

Summary
There are n dragon heads and m knights. Each dragon head has a diameter and each knight has a height. A dragon head with diameter D can be chopped off by a knight with height H if D <= H. A knight can only chop one dragon head. Given a list of diameters of the dragon heads and a list of heights of the knights. Is it possible to chop off all the dragon heads? If yes, what is the minimum total heights of the knights used to chop the dragon heads.

Explanation
Stay ahead greedy strategy works: each dragon head is chopped by a knight with the shortest height that is at least as tall as the diameter of the dragon's head. To find such knight, a binary search will do.

Implementations

 * Code All the Problems