0
点赞
收藏
分享

微信扫一扫

UVa Dragon of Loowater 11292 (贪心)


Once upon a time, in theKingdom of Loowater, a minornuisance turned into amajor problem.The shores of RellauCreek in central Loowaterhad always been a primebreeding ground for geese.Due to the lack of predators,the geese population was outof control. The people ofLoowater mostly kept clearof the geese. Occasionally,a goose would attack one ofthe people, and perhaps biteoff a finger or two, but ingeneral, the people toleratedthe geese as a minor nuisance.One day, a freak mutationoccurred, and oneof the geese spawned amulti-headed fire-breathingdragon. When the dragon grew up, he threatened to burn the Kingdom of Loowater to a crisp.Loowater had a major problem. The king was alarmed, and called on his knights to slay the dragonand save the kingdom.The knights explained: “To slay the dragon, we must chop off all its heads. Each knight can chopoff one of the dragon’s heads. The heads of the dragon are of different sizes. In order to chop off ahead, a knight must be at least as tall as the diameter of the head. The knights’ union demands thatfor chopping off a head, a knight must be paid a wage equal to one gold coin for each centimetre of theknight’s height.”Would there be enough knights to defeat the dragon? The king called on his advisors to help himdecide how many and which knights to hire. After having lost a lot of money building Mir Park, theking wanted to minimize the expense of slaying the dragon. As one of the advisors, your job was tohelp the king. You took it very seriously: if you failed, you and the whole kingdom would be burnt toa crisp!InputThe input contains several test cases. The first line of each test case contains two integers between 1 and20000 inclusive, indicating the number n of heads that the dragon has, and the number m of knights inthe 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 ofLoowater, also in centimetres.The last test case is followed by a line containing ‘0 0’.OutputFor each test case, output a line containing the minimum number of gold coins that the king needs topay to slay the dragon. If it is not possible for the knights of Loowater to slay the dragon, output theline ‘Loowater is doomed!’.

Sample Input

2 3

5

4

7

8

4

2 1

5

5

10

0 0

Sample Output

11

Loowater is doomed!

#include<stdio.h>
#include<string.h>
#include<algorithm>
#define ll long long
#define N 10010
using namespace std;
int a[20010];
int b[20010];
int main()
{
	int n,m;
	int i,j,k;
	while(scanf("%d%d",&n,&m),n|m)
	{
		for(i=0;i<n;i++)
			scanf("%d",&a[i]);
		for(i=0;i<m;i++)
			scanf("%d",&b[i]);
		if(n>m)
			printf("Loowater is doomed!\n");
		else
		{
			int sum=0;
			sort(a,a+n);
			sort(b,b+m);
			for(i=0,j=0;i<n&&j<m;)
			{
				if(b[j]>=a[i])
				{
					sum+=b[j];
					i++;j++;
				}
				else
					j++;	
			}
			if(i==n)
				printf("%d\n",sum);
			else
				printf("Loowater is doomed!\n");
		}
	}
	return 0;
}

 

 

举报

相关推荐

0 条评论