思路
维护一个小根堆,按照力量从小到大排序,结构体重载重载大于号,因为默认大根堆,如果是大根堆重载小于号,小根堆重载大于号。
因为我们只需要关心力量对伤害的影响,因此只需要模拟每一状态下的最小力量。而只要不断统计累计伤害,生命值无论是多少都可以通过累计伤害来判断是否已经死亡。
注意小根堆定义时第三个参数后面没有括号,这和从大到小定义排序函数不一样,后者是有括号的。
代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=2e5+5;
ll t,n,m,x,y,k;
struct node{
ll h,p;
bool friend operator > (const node A, const node B){
return A.p > B.p;
}
}a[maxn];
priority_queue<node,vector<node>,greater<node>>q;
int main()
{
cin>>t;
while(t--){
cin>>n>>k;
for(ll i=1;i<=n;i++)cin>>a[i].h;
for(ll i=1;i<=n;i++)cin>>a[i].p;
while(q.size())q.pop();
for(ll i=1;i<=n;i++)q.push(a[i]);
ll cur=k;
bool flag=true;
while(q.size()){
node now;
now = q.top();
q.pop();
if(cur<now.h){
q.push(now);
k-=now.p;
if(k<=0){
flag=false;
break;
}
cur+=k;
}
}
if(flag==false)puts("NO");
else puts("YES");
}
return 0;
}