# Uva11292 The Dragon of Loowater

88人阅读 评论(0)

Input Theinputcontainsseveraltestcases. Thefirstlineofeachtestcasecontainstwointegersbetween1and 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

2 1

10

0 0

Sample Output

11

Loowater is doomed!

#include <stdio.h>
#include <stdlib.h>
#define maxn 200000
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int a[maxn],b[maxn];

int cmp(const void*a,const void*b)
{
return *(int*)a-*(int*)b;
}
int main(int argc, char *argv[])
{
int n,m,c;
int i,j;
while((scanf("%d%d",&n,&m))!=-1&&n+m!=0)
{
c=0;
for(i=0;i<n;i++)
scanf("%d",&a[i]);
qsort(a,n,sizeof(int),cmp);
for(j=0;j<m;j++)
scanf("%d",&b[j]);
qsort(b,m,sizeof(int),cmp);
j=0;
for(i=0;i<m;i++)
{
if(b[i]>=a[j])
{
c+=b[i];
if(++j==n)
break;
}
}
if(j<n)
printf("Loowater is doomed!\n");
else
printf("%d\n",c);
}

return 0;
}

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：3131次
• 积分：296
• 等级：
• 排名：千里之外
• 原创：28篇
• 转载：0篇
• 译文：0篇
• 评论：0条
文章分类
阅读排行
评论排行