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 geese population was 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 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."

Would there be enough knights to defeat the dragon? The king called on his advisors to help him decide how many 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 would be burnt to a crisp!

Input

The input contains several test cases. The first line of each test case contains two integers between 1 and 20000 inclusive, indicating the number n of heads that the dragon has, and the number m of knights in the kingdom. The next n lines each contain an integer, and give the diameters of the dragon's heads, in centimetres. The following m lines 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

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 3
5
4
7
8
4
2 1
5
5
10
0 0

Sample Output

11
Loowater is doomed! 题解: 贪心,每次用最没用代价最小的骑士去打龙,能搞定就搞定,不能搞定就不用他了。 代码:
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#define MAXN 30000
using namespace std;
int n,m;
int d[MAXN],p[MAXN];
int main(){
while(){
memset(d,,sizeof(d));
memset(p,,sizeof(p));
scanf("%d%d",&n,&m);
if(!n&&!m) break;
for(int i=;i<=n;i++) scanf("%d",&d[i]);
for(int i=;i<=m;i++) scanf("%d",&p[i]);
sort(d+,d+n+),sort(p+,p+m+);
int i=,j=,tot=;
while(i<=m&&j<=n){
if(p[i]>=d[j]) j++,tot+=p[i];
i++;
}
if(j<=n) printf("Loowater is doomed!\n");
else printf("%d\n",tot);
}
}

POJ - 3646 The Dragon of Loowater的更多相关文章

  1. The Dragon of Loowater

      The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into ...

  2. uva-----11292 The Dragon of Loowater

    Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...

  3. uva 11292 Dragon of Loowater (勇者斗恶龙)

    Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...

  4. UVA它11292 - Dragon of Loowater

    Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...

  5. UVA 11292 Dragon of Loowater(简单贪心)

    Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...

  6. Dragon of Loowater

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=2267" style="color:b ...

  7. 贪心/思维题 UVA 11292 The Dragon of Loowater

    题目传送门 /* 题意:n个头,m个士兵,问能否砍掉n个头 贪心/思维题:两个数组升序排序,用最弱的士兵砍掉当前的头 */ #include <cstdio> #include <c ...

  8. Uva11292--------------(The Dragon of Loowater)勇者斗恶龙 (排序后贪心)

    ---恢复内容开始--- 题目: Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major ...

  9. [ACM_水题] UVA 11292 Dragon of Loowater [勇士斗恶龙 双数组排序 贪心]

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

随机推荐

  1. mybatis 批量插入时候的一个注意点

    <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys=&quo ...

  2. MySQL Explain学习笔记

    目录 一.执行计划概念 二.Explain用法 三.Explain属性介绍 3.1 id属性 3.2 select_type属性 3.3 table属性 3.4 type属性 3.5 possible ...

  3. MySql(二)_NHibernateHelper管理会话工厂

    1.定义接口的好处: (1) 清楚的看到里面有哪些方法: ( 2 )  可以更换实现类:Nhibernate实现件可以更换: Manger文件夹(另外两个是Model.Mappings文件夹) 首先M ...

  4. 设置IntelliJ IDEA支持lambda表达式

    使用IntelliJ IDEA做为开发工具,对基于maven的java工程,如果要编写lambda表达式,先确保安装并使用了jdk1.8或者更高版本,然后再要做一些设置才能正常编译和执行,具体表现在m ...

  5. Web之-----弹出确认框控件应用

    引用文件!-------- <link rel="stylesheet" type="text/css" href="@Url.FrontUrl ...

  6. 不用JS,教你只用纯HTML做出几个实用网页效果

    转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者.原文出处:https://blog.bitsrc.io/pure-html-widgets-for-your- ...

  7. 即时聊天APP(五) - 聊天界面

    设置界面没什么好说的,无非也就是加了个对话框来二次提醒用户,现在来讲讲聊天界面. 聊天界面初始化时会得到一个参数,就是对方的id,并设置在标题栏的位置,此界面也是使用RecyclerView来展示聊天 ...

  8. Aspose.Cell导出带chart图表

    最终实现的效果就是这样,代码比较多,我放在了CSDN上了,是无需模板的,别听网上瞎吹,说什么要模板,地址是:https://download.csdn.net/download/chanelwtt/1 ...

  9. pip安装Mysql-python报错EnvironmentError: mysql_config not found

    如下图,安装Mysql-python报错EnvironmentError: mysql_config not found 经过验证,可通过以下方式解决: 从官网下载mysql安装,成功之后输入PATH ...

  10. VS Code中无法识别npm命令

    今天在VS Code中执行npm install命令时报了“'npm' 不是内部或外部命令,也不是可运行的程序或批处理文件”的错误. 首先检查环境变量是否配置正常: 系统变量中NODE_PATH,变量 ...