思路:
跟上题类似,贪心策略:w从小到大排序,每个头找到第一个>=d的w
代码:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 10;
int n, m;
int d[N];
int w[N];
int v[N]; // 勇士是否被使用
int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cin >> n >> m;for (int i = 1; i <= n; i++){cin >> d[i];}sort(d + 1, d + 1 + n);for (int i = 1; i <= m; i++){cin >> w[i];}sort(w + 1, w + 1 + m);int j = 1;for (int i = 1; i <= n; i++){ // dint flag = 0;for (; j <= m; j++){ // w// 找第一个>=d的wif (v[j] == 0 && w[j] >= d[i]){v[j] = 1;flag = 1;break;}}if (flag == 0){ // 有头没有勇士能消灭cout << "NO" << endl;return 0;}}cout << "YES" << endl;return 0;
}