#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#pragma warning(disable:4996)
#include<cstdio>
#include<cstdlib>
using std::cin;
using std::cout;
using std::endl;
using std::stringstream;
using std::string;
using std::vector;
using std::list;
using std::pair;
using std::set;
using std::multiset;
using std::map;
using std::multimap;
using std::stack;
using std::queue;
using std::priority_queue;
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int n, m;
while (cin >> n >> m && (n + m))
{
vector<int>dragon(n), knight(m);
for (int i = 0; i < n; i++)
{
cin >> dragon[i];
}
for (int i = 0; i < m; i++)
{
cin >> knight[i];
}
if (n > m)//如果龙的数量大于骑士的数量,显然屠龙失败
{
cout << "Loowater is doomed!" << endl;
continue;
}
std::sort(dragon.begin(), dragon.end());
std::sort(knight.begin(), knight.end());
int cost = 0, killed = 0;
for (int i = 0,j=0;i<n&&j<m;j++)
{
if (dragon[i] <= knight[j])//如果龙的血量小于等于骑士的战斗力,即屠龙成功
{
cost += knight[j];
i++;//跳到下一条龙
killed++;//屠龙数+1
}
}
//如果屠龙数量==龙的数量,输出已屠龙的数量
if (killed == n)
{
cout << cost << endl;
}
else
{
cout << "Loowater is doomed!" << endl;
}
}
return 0;
}
UVA_11292_Dragon of Loowater
最新推荐文章于 2016-05-21 12:22:02 发布