/*
从算法竞赛入门经典训练指南上看到的题目,大概意思是有一条n个头的龙,m个勇士,每个勇士能力为x,雇佣价格也为x,每个勇士能砍掉不龙一个直径不超过x的头,如何雇佣是雇佣价格最少(贪心)
注意:每个勇士只能砍一个头且不能被雇佣两次
*/
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cstdio>
using namespace std;
const int maxn = 20000+10;
int a[maxn];//每个头直径
int b[maxn];//骑士能力
int main()
{
int n,m;//头数,骑士数量
while(scanf("%d%d",&n,&m)==2 && n && m)
{
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<m;i++) cin>>b[i];
int cost=0;//所需金币
sort(a,a+n);
sort(b,b+m);
int cur=0;
for(int i=0;i<m;i++)
{
if(b[i]>=a[cur])
{
cost=cost+b[i];
if(++cur==n) break;
}
}
if(cur<n)
printf("Loowater is doomed!\n");
else
cout<<cost<<endl;
}
return 0;
}
UVA11292
最新推荐文章于 2018-07-09 20:30:31 发布