很简单的一道题,输入完骑士和恶龙后,sort排序,然后扫面骑士,发现骑士大于等于恶龙,费用就加,否则继续循环,直到恶龙到n及时跳出循环:
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 20000 + 5;
int Knight[maxn];
int Dragon[maxn];
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m) && m && n){
for (int i = 0; i < n; ++i)scanf("%d",&Dragon[i]);
for (int i = 0; i < m; ++i)scanf("%d",&Knight[i]);
sort(Dragon, Dragon + n);
sort(Knight, Knight + m);
int cost = 0,cur = 0;
for (int i = 0; i < m; ++i){
if (Knight[i] >= Dragon[cur]){
cost += Knight[i];
if (++cur == n)break;
}
}
if (cur < n)printf("Loowater is doomed!\n");
else printf("%d\n",cost);
}
return 0;
}