贪心策略:
1.若b>=a,则a小的放在前面,减少丧失的稳定性,以防下一个a过大.
2.若b<a,则b大的放在前面.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5e5+5;
inline ll read()
{
ll s = 0, w = 1;
char ch = getchar();
while (ch < 48 || ch > 57)
{
if (ch == '-')
w = -1;
ch = getchar();
}
while (ch >= 48 && ch <= 57)
s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
return s * w;
}
struct node
{
int a,b;
bool operator < (const node n) const
{
if(b >= a && n.b >= n.a)
return a < n.a;
if(b >= a)
return true;
if(n.b >= n.a)
return false;
return b > n.b;
}
}q[500005];
int main(int argc, char const *argv[])
{
int t = read();
while(t--)
{
ll n = read(), m = read();
for (int i = 0; i < n; ++i)
{
q[i].a = read();
q[i].b = read();
}
sort(q, q+n);
bool flag = true;
for (int i = 0; i < n; ++i)
{
if (m < q[i].a)
{
flag = false;
break;
}
m += (q[i].b - q[i].a);
}
if (flag)
{
cout << "Yes" << endl;
}
else
cout << "No" << endl;
}
return 0;
}