#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<cctype>
#include<sstream>
using namespace std;
#define pii pair<int,int>
#define LL long long int
const int eps=1e-;
const int INF=;
const int maxn=+;
int n,m,a[maxn],b[maxn],sum;
int main()
{
//freopen("in1.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(scanf("%d%d",&n,&m)==)
{
if(m==&&n==)
{
break;
}
else
{
sum=;
for(int i=; i<n; i++)
{
scanf("%d",&a[i]);
}
for(int i=; i<m; i++)
{
scanf("%d",&b[i]);
}
if(n>m)
{
printf("Loowater is doomed!\n");
}
else
{
int tn=n,tm=m,j=,i=;
sort(a,a+n);
sort(b,b+m);
for(i=; i<n; i++)
{
if(tn>tm||j>=m)
{
break;
}
else
{
for(; j<m; j++)
{
if(a[i]<=b[j])
{
sum+=b[j];
tm--;
tn--;
j++;
/*这里的j++非常重要,必须加,因为不加
的话下一次循环还是先从上次这个j开始判断一
遍再进行下一次循环。(如果for里写成
++j效果和j++一样的),这也是for循环
中易犯的错误。*/
break;
}
else
{
tm--;
}
}
}
}
if(i==n)
{
printf("%d\n",sum);
}
else
{
printf("Loowater is doomed!\n");
}
}
}
}
//fclose(stdin);
//fclose(stdout);
return ;
}

最新文章

  1. EntityFramework错误:Unable to update the EntitySet because it has a DefiningQuery
  2. python os.path模块
  3. 如果用css的border属性画一个三角形
  4. Python基础、异常处理
  5. C# 不同版本切版时,方法不支持,加载对应dll, 相关Dll的资源
  6. 自定义控件--CircleImageView(类似于QQ、微信圆形头像自定义控件)
  7. Linux之convert命令
  8. Java实现分页数据获取CachedRowSet
  9. POJ 3694 LCA
  10. Jmeter+badboy环境搭建
  11. ADO.NET知识点
  12. 【实验吧】CTF_Web_简单的SQL注入之3
  13. OpenCV——PS图层混合算法(六)
  14. 基于C#简单实现多个word文件和Excel文件的全局字符串替换
  15. CF1108F MST Unification
  16. Mysql建库建用户建表等常用命令
  17. 使用xshell+xmanager+pycharm搭建pytorch远程调试开发环境
  18. [转]springboot2 webflux 响应式编程学习路径
  19. 在VS2017上使用C#调用非托管C++生成的DLL文件(图文讲解)
  20. 第一讲(3)osgearth编译

热门文章

  1. django基本安装
  2. Hadoop学习基础之三:MapReduce
  3. Hibernate Student_Course_Score设计
  4. springboot-整合freemarker
  5. Delphi中ComPort通信中的数据处理
  6. Python编程-网络编程进阶(IO复用、Socketserver)
  7. oracle长连接超时设置
  8. 快乐学习 Ionic Framework+PhoneGap 手册1-5 {IO开关}
  9. redis 第一篇
  10. Centos6.5使用yum安装软件的时候 Another app is currently holding the yum lock; waiting for it to exit...