记录编号 72005 评测结果 AAAAAAAAAA
题目名称 [UVa 11292] 勇者斗恶龙 最终得分 100
用户昵称 Gravatarcstdio 是否通过 通过
代码语言 C++ 运行时间 0.024 s
提交时间 2013-10-14 19:31:25 内存使用 0.31 MiB
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<set>
#include<algorithm>
using namespace std;
int m,n;
int cost=0;
multiset<int,greater<int> > heads;
multiset<int> knights;
void read(void){
	scanf("%d%d",&n,&m);
	int i,temp;
	for(i=1;i<=n;i++) scanf("%d",&temp),heads.insert(temp);
	for(i=1;i<=m;i++) scanf("%d",&temp),knights.insert(temp);
}
void work(void){
	multiset<int,greater<int> >::iterator keyh;
	multiset<int>::iterator keyk;
	while(!heads.empty()){
		keyh=heads.begin();
		keyk=knights.lower_bound(*keyh);
		if(keyk==knights.end()){
			printf("Loowater is doomed");
			return;
		}
		cost+=*keyk;
		heads.erase(keyh);
		knights.erase(keyk);
	}
	printf("%d\n",cost);
}
int main(){
	freopen("DragonUVa.in","r",stdin);
	freopen("DragonUVa.out","w",stdout);
	read();
	work();
	return 0;
}