从今天开始刷刘汝佳的白书了 争取每天能刷到10道以上
而做的每一道我都会写题解 由于时间原因 就不再照着书把题意打上来了
这题是一个简单的贪心 由每个龙头从小到大排好去找能砍它的骑士 开始自己想到了 然后就把骑士存在multiset里了
每次 lower_bound找到 再删掉 但这样会较慢一些 其实可以线性的跑过去 果然stl用习惯了就会有依赖性。。。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#define scnaf scanf
#define cahr char
#define bug puts("bugbugbug");
using namespace std;
typedef long long ll;
const int mod=1000000007;
const int maxn=20005;
const int inf=1e9;
const int maxe=200000;
int a[maxn],b[maxn];
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m)&& n && m)
{
int ans=0;
int flag=1;
for(int i=0;i<n;i++)
scanf("%d",a+i);
for(int i=0;i<m;i++)
scanf("%d",b+i);
sort(a,a+n);
sort(b,b+m);
int cnt=0;
for(int i=0;i<n;i++)
{
while(b[cnt]<a[i]&&cnt<m) cnt++;
if(cnt==m){
flag=0;break;
}
ans+=b[cnt++];
}
if(flag)
printf("%d\n",ans);
else
puts("Loowater is doomed!");
}
return 0;
}