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. 使用display:flex;实现垂直水平居中

    body,div{margin:0px;padding:0px;} .flex-container{display:flex;height:300px;background-color:#ddd;ju ...

  2. P2085最小函数值(优先队列)

    P2085 最小函数值(minval) 题目描述 有n个函数,分别为F1,F2,...,Fn.定义Fi(x)=Ai*x^2+Bi*x+Ci (x∈N*).给定这些Ai.Bi和Ci,请求出所有函数的所有 ...

  3. phonegap+cordova+ionic调用原生API

    上一篇博客讲了phonegap+cordova+ionic的环境搭建,今天再来分享一篇cordova调用原生API的文章.从技术角度上来讲,这并不是很难,只是有些细节要是没有注意,或者某些步骤不知道的 ...

  4. Appium + python -yaml配置文件

    在线安装:pip install yaml import yamlimport os # 获取当前脚本所在文件夹路径curpath = os.path.dirname(os.path.realpath ...

  5. JSP所需要掌握的部分

    JSP基本语法 指令 <%@ 指令%> JSP指令是JSP的引擎 主要的两种指令是page和include(taglib) <%@ page import="java.ut ...

  6. [ NOIP 2009 ] TG

    \(\\\) \(\#A\) \(Spy\) 给出两个长度均为\(N\)相同的样例串,建立第一个串各个字符向第二个串对应位置字符的映射,并用映射转换给出的长度为\(M\)第三个串,输入保证只有大写字符 ...

  7. 【转】utf-8的中文是一个汉字占三个字节长度

    因为看到百度里面这个人回答比较生动,印象比较深刻,所以转过来做个笔记 原文链接 https://zhidao.baidu.com/question/1047887004693001899.html 知 ...

  8. Android 控制硬加速 hardwareAccelerated

    从Android3.0 (API level11)开始,Android的2D显示管道被被设计得更加支持硬加速了.硬加速使用GPU承担了所有在View的canvas上执行的绘制操作. 启用硬加速最简单的 ...

  9. Mac sierra下 wget安装

    本文由@ray 出品,转载请注明出处.  文章链接:http://www.cnblogs.com/wolfray/p/8040699.html 没有Wget的日子是非常难过的,强大的Mac OS 下安 ...

  10. win32绘图基础

     获取设备环境句柄: (1)WM_PAINT消息中: PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd,&ps); EndPaint(hwnd,&ps ...