#include<stdio.h>
#include<string.h>
int dh[20010],kh[20010];
void Qsort(int start,int length,int a[])
{
int x = a[start];
int i,j;
i = start;
j = length -1;
while(i < j)
{
if(x < a[j])
j--;
else if(x > a[j])
{
a[i] = a[j];
a[j] = x;
i++;
}
else if(x < a[i])
{
a[j] = a[i];
a[i] = x;
j--;
}
else
i++;
}
if(start < length-1)
{
Qsort(start,i,a);
Qsort(i+1,length,a);
}
}
int main()
{
int n,m,i,j,t,count=0,c=0;
while(1)
{
scanf("%d%d",&n,&m);
memset(dh,0,sizeof(dh));
memset(kh,0,sizeof(kh));
if(n==0&&m==0)
{
break;
}
for(i=0;i<n;i++)
{
scanf("%d",&dh[i]);
}
for(i=0;i<m;i++)
{
scanf("%d",&kh[i]);
}
if(n>m)
{
printf("Loowater is doomed!\n");
}
else
{
Qsort(0,n,dh);
Qsort(0,m,kh);
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(dh[j]>dh[j+1])
{
t=dh[j];
dh[j]=dh[j+1];
dh[j+1]=t;
}
}
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(kh[j]>=dh[i])
{
c++;
count+=kh[j];
kh[j]=0;
j=m-1;
}
}
}
if(c<n)
{
printf("Loowater is doomed!\n");
}
else
{
printf("%d\n",count);
}
}
count=0;
c=0;
}
return 0;
}
HDU The Dragon of Loowater
最新推荐文章于 2016-08-04 23:14:25 发布