/*
* UVA_11292.cpp
*
* Created on: 2013年11月17日
* Author: Administrator
*/
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int maxn =20010;
int a[maxn];
int b[maxn];
int main(){
int n,m;
while(scanf("%d%d",&n,&m)!=EOF,n||m){
int i;
for(i = 0 ; i < n ; ++i){
scanf("%d",&a[i]);
}
for(i = 0 ; i < m ; ++i){
scanf("%d",&b[i]);
}
sort(a,a+n);
sort(b,b+m);
int cur = 0;
int cost = 0;
for(i = 0 ; i < m ; ++i){
if(b[i] >= a[cur]){
cost += b[i];
if(++cur == n){
break;
}
}
}
if(cur < n){
printf("Loowater is doomed!\n");
}else{
printf("%d\n",cost);
}
}
return 0;
}
(UVA step1)UVA 11292 The Dragon of Loowater(有n条恶龙,m个骑士,求杀死恶龙的最小代价)
原创
©著作权归作者所有:来自51CTO博客作者CAIHONGSHIJIE6的原创作品,请联系作者获取转载授权,否则将追究法律责任

提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
例题5-1 UVA 11292 The Dragon of Loowater勇者斗恶龙
很简单的一道题,int Dragon[maxn];int main(){ int n,m;
c语言 uva #include 跳出循环 sort排序 -
UVA它11292 - Dragon of Loowater
Problem C: The Dragon of LoowaterOnce upon a time, in the Kingdom of Lo
i++ #include ide desktop php