uva 11292

不墨迹

#include 
#include 
using namespace std;
const int maxn = 1e6;
int a[maxn], b[maxn];
int main()
{

#ifndef ONLINE_JUDGE
    freopen("in", "r", stdin);
#endif
    int n, m;
    while (cin >> n >> m)
    {
        if (n == 0 && m == 0)
            break;
        for (int i = 0; i < n; i++)
            cin >> a[i];
        for (int i = 0; i < m; i++)
            cin >> b[i];
        sort(a, a + n);
        sort(b, b + m);
        int i = 0;
        int j = 0;
        int sum = 0;
        while (i < n && j < m)
        {
            if (a[i] <= b[j])
            {
                sum += b[j];
                ++i, ++j;
            }
            else
            {
                ++j;
            }
        }
        if (i == n)
        {
            cout << sum << endl;
        }
        else
        {
            cout << "Loowater is doomed!" << endl;
        }
    }
} 

你可能感兴趣的:(uva 11292)