首页 > 代码库 > uva11292 Dragon of Loowater

uva11292 Dragon of Loowater

水题,排序遍历即可

#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

const int maxn = 20010;
int drag[maxn], kn[maxn];
int main()
{
    int n, m, cost;
    while (cin >> n >> m) {
        if(n == 0 && m == 0)break;
        for (int i = 0;i < n;i++)cin >> drag[i];
        for (int i = 0;i < m;i++)cin >> kn[i];
        sort(drag, drag + n);
        sort(kn, kn + m);
        int cur = 0;
        cost = 0;
        for (int i = 0;i < m;i++) {
            if (kn[i] >= drag[cur]) {
                cost += kn[i];
                if (++cur == n)break;
            }
        }
        if (cur < n)cout << "Loowater is doomed!" << endl;
        else cout << cost << endl;
    }
    return 0;
}

 

uva11292 Dragon of Loowater