题目:Problem - 7087 (hdu.edu.cn)
题解:1.每次更新最大存储剩余空间去存储
#include<iostream>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
const int N = 1e5+1;
int a[N];
bool cmp(int a, int b)
{
return a > b;
}
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
int n, m;
scanf("%d %d", &n, &m);
priority_queue<int>heap;//最大剩余空间
for (int i = 0; i < n; ++i)
{
cin >> a[i];
}
for (int i = 0; i < m; i++)
{
int x;
cin >> x;
heap.push(x);
}
sort(a, a + n, greater<int>());
bool first = true;
for (int i = 0; i < n; i++)
{
if (heap.size() && heap.top() >= a[i])//采用贪心 即最大剩余空间对应最大的存储量
{
int t = heap.top();
heap.pop();
heap.push(t - a[i]);
}
else
{
first = false;
break;
}
}
if (first)
{
printf("Yes\n");
}
else
{
printf("No\n");
}
}
}