复制代码

uva 11292

不墨迹

#include <iostream>
#include <algorithm>
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;
        }
    }
} 
posted @ 2020-06-26 17:20  pg633  阅读(91)  评论(0编辑  收藏  举报