水题,直接贴代码。
//poj 3646
//sep9
#include <iostream>
#include <algorithm>
using namespace std;
const int maxN=20012;
int a[maxN],b[maxN];int main()
{int n,m;while(scanf("%d%d",&n,&m)==2&&n+m){int i,j;for(i=0;i<n;++i)scanf("%d",&a[i]);for(i=0;i<m;++i)scanf("%d",&b[i]); sort(a,a+n);sort(b,b+m);int sum=0;for(i=0,j=0;i<n&&j<m;)if(a[i]<=b[j]){sum+=b[j];++i,++j;}else++j; if(i==n)printf("%d\n",sum);elseprintf("Loowater is doomed!\n"); }return 0;
}