UVA 11292 Dragon of Loowater

#include <cstdio>
#include <algorithm>
using namespace std;

#define MAX 25000
int main()
{
    int n, m, i, j, val;
    int q[MAX], l[MAX];

    while(scanf("%d%d", &n, &m) != -1 && n && m)
    {
        val = 0;
        for(i=0; i<n; i++)
            scanf("%d", &l[i]);
        for(i=0; i<m; i++)
            scanf("%d", &q[i]);
        if(n < m)
        {
            sort(l, l+n);
            sort(q, q+m);
            for(i=0,j=0; i<n;)
            {
                if(l[i] <= q[j])
                {
                    val += q[j];
                    i++;j++;
                }
                else
                    j++;
                if(j >= m)
                    break;
                //printf("%d ", val);
            }
            if(i < n-1)
                printf("Loowater is doomed!\n");
            else
                printf("%d\n", val);
        }
        else
        {
            printf("Loowater if doomed!\n");
        }
    }
    return 0;
}

你可能感兴趣的:(刘汝佳)