주제 링크 : HTTPS : //ac.nowcoder.com/acm/contest/2272/H의
효과에 따라 :
아이디어 :하자, 그럼 0>의 양을 증가, 순 증가를 계산 확실히는 [I] 작은입니다 앞에서.
<0의 양을 증가시키는 경우에 대해. 우리는 B [i]를 행 순.
증명 :의 돌 앞의 최소의 내구성이다.
<0의 순 증가 : 그리고 추가 증거를 제공합니다. B 이외에 [N] 최소의 값을 취한다. 효과 없음 어떤 다른 종류.
#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;
}