https://codeforces.com/gym/102916/problem/K
首先对于所有h=min(h,m)
对于t<=h的,由于它可以更换攻击目标,反正我可以让他们只剩最后一滴血,然后留着最后一滴血的时候再用,就等于备用血包
然后对于t>h的,按h下降顺序排序
In what order should we process enemies from the second group? The right answer is by decreasing hi values. If you process two enemies i and j with hi < hj , you better swap them, processing j first, because your hp will be higher after the first regeneration (after j), and be the same after the second regeneration (after i). If you don’t swap them, the order i, j may fail you because you may not regenerate enough hp after killing i.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxl=2e5+10;
int n,m,ans,cnt;
int t[maxl],h[maxl];
struct node
{
int t,h;
}a[maxl];
inline void prework()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d%d",&t[i],&h[i]),h[i]=min(h[i],m);
}
inline bool cmp(const node &a,const node &b)
{
return a.h>b.h;
}
inline void mainwork()
{
ll res=m;cnt=0;
for(int i=1;i<=n;i++)
if(t[i]<=h[i])
res+=h[i]-t[i];
else
a[++cnt]=node{t[i],h[i]};
sort(a+1,a+1+cnt,cmp);
ans=1;
for(int i=1;i<=cnt;i++)
{
res-=a[i].t;
if(res<0)
ans=0;
res+=a[i].h;
}
}
inline void print()
{
puts(ans?"YES":"NO");
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
prework();
mainwork();
print();
}
return 0;
}