样例过求条
查看原帖
样例过求条
1605910
jasonmazhihan楼主2025/6/23 20:38
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
    for (int n, m; cin >> n >> m && n && m;)
    {
        int heads[n], soilders[m], ans = 0, cur = 0;
        bool doom = false;
        for (int i = 0; i < n; i++)
            cin >> heads[i];
        sort(heads, heads + n);
        for (int i = 0; i < m; i++)
            cin >> soilders[i];
        sort(soilders, soilders + m);
        for (int i = 0; i < n; i++)
        {
            int a = ans;
            for (int j = cur; j < m; j++)
                if (heads[i] <= soilders[j])
                {
                    cur = j + 1;
                    ans += soilders[j];
                    break;
                }
            if (a == ans)
            {
                cout << "Loowater is doomed!\n";
                doom = true;
                break;
            }
        }
        if (doom)
            continue;
        cout << ans << endl;
    }
    return 0;
}```
2025/6/23 20:38
加载中...