uva11292-Dragon of Loowater

#include<iostream>
using namespace std;
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>

const int maxn=20005;
int a[maxn];
int b[maxn];
bool used[maxn];

int main(){
    int n,m;
    while(scanf("%d%d",&n,&m)!=-1){
        if(n==0&&m==0)break;
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        for(int i=0;i<m;i++){
            scanf("%d",&b[i]);
        }
        int ans=0;
        bool judge=true;
        if(n>m){
            judge=false;
        }
        else{
            memset(used,false,sizeof(used));
            sort(b,b+m);
            //cout<<b[0]<<" "<<b[1]<<endl;
            for(int i=0;i<n;i++){
                int pos=lower_bound(b,b+m,a[i])-b;
                bool j_=true;
                for(int j=pos;j<m;j++){
                    if((!used[j])&&(b[j]>=a[i])){
                        used[j]=true;
                        j_=false;
                        ans+=b[j];
                        break;
                    }
                }
                judge=!j_;
                if(!judge)break;
            }
        }
        if(judge)printf("%d\n",ans);
        else{
            puts("Loowater is doomed!");
        }
    }
    return 0;
}

你可能感兴趣的:(uva11292-Dragon of Loowater)