Topic link: https: //ac.nowcoder.com/acm/contest/2272/H
subject to the effect:
idea: Let's count the net increase, then to increase the amount of> 0, certainly is a [i] is smaller In front of.
For the case of increasing the amount of <0. We descending order of b [i] row.
Proof: s is the minimum endurance in front of the stone.
And give an additional proof: the net increase in <0. In addition to B [n] takes a minimum value. What other sort of no effect.
#include <bits/stdc++.h>
#define LL long long
using namespace std;
struct node{
LL a, b, c;
}a[500005];
int cmp(node &a, node &b){
if(a.c>=0&&b.c>=0){
return a.a<b.a;
}
else if(a.c<0&&b.c<0){
return a.b>b.b;
}
else{
return a.c>b.c;
}
}
int main()
{
int t;
scanf("%d", &t);
while(t--){
LL n, m;
scanf("%lld%lld", &n, &m);
for(int i=1; i<=n; i++){
scanf("%lld%lld", &a[i].a, &a[i].b);
a[i].c=a[i].b-a[i].a;
}
sort(a+1, a+1+n, cmp);
for(int i=1; i<=n; i++){
m-=a[i].a;
if(m<0){
break;
}
else{
m+=a[i].b;
}
}
if(m>=0){
printf("Yes\n");
}
else{
printf("No\n");
}
}
return 0;
}