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<cstdio>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<fstream>
#include<memory>
#include<string>
using namespace std;
typedef long long LL;
#define MAXN 20006
#define INF 1000000009
/*
花费尽量少:要求用能砍掉的最矮的骑士即可
*/
int head[MAXN], n, m;
vector<int> knight;
int main()
{
while (scanf("%d%d", &n, &m), n + m)
{
knight.clear();
for (int i = ; i < n; i++)
scanf("%d", &head[i]);
int tmp;
for (int i = ; i < m; i++)
{
scanf("%d", &tmp);
knight.push_back(tmp);
}
sort(knight.begin(), knight.end());
int ans = ;
vector<int>::iterator it;
int t;
for ( t = ; t < n; t++)
{
it = lower_bound(knight.begin(), knight.end(),head[t]);
if (knight.empty()||it == knight.end())
break;
else
{
ans += *it;
knight.erase(it);
}
}
if (t!=n)
printf("Loowater is doomed!\n");
else
printf("%d\n", ans);
}
}

L - 贪心 基础的更多相关文章

  1. L贪心基础

    <span style="color:#330099;">/* L - 贪心 基础 Time Limit:1000MS Memory Limit:65536KB 64b ...

  2. poj2709 贪心基础

    D - 贪心 基础 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     64bi ...

  3. uva11292贪心基础题目

    C - 贪心 基础 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     64bi ...

  4. hdu 1009 贪心基础题

    B - 贪心 基础 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     64bi ...

  5. Problem L: 搜索基础之马走日

    Problem L: 搜索基础之马走日 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 134  Solved: 91[Submit][Status][W ...

  6. - > 贪心基础入门讲解一——完美字符串

    约翰认为字符串的完美度等于它里面所有字母的完美度之和.每个字母的完美度可以由你来分配,不同字母的完美度不同,分别对应一个1-26之间的整数. 约翰不在乎字母大小写.(也就是说字母F和f)的完美度相同. ...

  7. BalkanOI 2018 Parentrises(贪心+基础DP)

    题意 https://loj.ac/problem/2713 思路 对于 \(\text{P1}\) 的档,首先可以看出 \(O(n^3)\) 的方法,即用 \(O(n^3)\) 的 \(\text{ ...

  8. 股神小L [贪心]

    题面 思路 股票题肯定是贪心或者$dp$啊 这个题比较$naive$,可以看出来你这里买股票的过程一定是能不买就不买,能卖就拣最贵的日子卖,而且时间不能倒流(废话= =||) 所以我们按照时间从前往后 ...

  9. - > 贪心基础入门讲解五——任务执行顺序

    分析: 本题可以抽象成,从一个整数开始,每次减去a,再加上b (a,b都是正数),要求每次操作都不产生负数. 针对本题a[i] = R[i], b[i] = R[i] – O[i],注意O[i] &l ...

随机推荐

  1. 【转】Java - printf

    [转自]http://heidian.iteye.com/blog/404632 目前printf支持以下格式:            %c        单个字符            %d     ...

  2. vs打开wixproj后缀文件

    1.在正常情况下vs是无法打开wixproj工程的,能打开也只能是以记事本方式打开该文件本身 2.所以此时需要下载wixtool,安装后即可打开上述类型文件 3.最好也安装好vs对应版本的扩展包 4. ...

  3. SpringBoot入门之HelloWorld

    1.SpringBoot简介 百度百科:Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而 ...

  4. git下

    ----------- 1. 分支管理策略 1)master分支 非常稳定的,只用来发布新版本,平时不在上面干活 2)dev分支 不稳定的,主要在上面干活,每个人都有自己的分支,时不时的往dev分支上 ...

  5. BZOJ 2592 随机化(伪)

    思路: 放yousiki大爷题解 http://yousiki.net/index.php/archives/82/ 我写的是随机化 既然gzz证了最终答案的上界是O(N)的 那么我们可以n^2枚举所 ...

  6. mysql远程服务器访问数据库

    创建一个MySQL用户,并设置可以远程访问 grant usage on *.* to 'fred'@'localhost' identified by 'fred';//创建用户fred密码ferd ...

  7. 快速搭建Hadoop及HBase分布式环境

    本文旨在快速搭建一套Hadoop及HBase的分布式环境,自己测试玩玩的话ok,如果真的要搭一套集群建议还是参考下ambari吧,目前正在摸索该项目中.下面先来看看怎么快速搭建一套分布式环境. 准备 ...

  8. overflow:解决 div的高度塌陷问题

    高度塌陷是如何引起的? 解析: 当一个 div中所有的子  div都进行了浮动后,那么会出现该问题,那么解决方就是在父 div中 设置其  overflow:hidden;即可解决高度塌陷问题. 方式 ...

  9. drupal 8 ——自定义权限

    在项目开发里面,我遇到了这么一个需求,就是对于node的title字段,编辑内容的角色不允许对title进行编辑.title字段是创建内容类型时自动生成的字段,不能在drupal8后台直接配置权限,所 ...

  10. JS高级——扩展内置对象的方法

    基本概念 内置对象有很多,几个比较重要的:Math.String.Date.Array 基本使用 1.内置对象创建出来的对象使用的方法使用的其实都是内置对象的原型对象中的方法 (1)a并没有charA ...