看题后可知是简单贪心即可(将孩子按各自的需要从小到大排序),排序要用快速排序哈,否则会超时.
代码:
#include
#include
using namespace std;
const int maxn = 10000 + 10;
struct node
{
int a;
int b;
bool operator < (const node& e) const
{
return b < e.b || (b == e.b && a > e.a);
}
}x[maxn];
int main()
{
int n,s;
while(~scanf("%d",&n))
{
if(!n) return 0;
scanf("%d",&s);
for(int i = 0; i < n; i++) scanf("%d%d",&x[i].a,&x[i].b);
sort(x,x+n);
bool ok = 1;
for(int i = 0; i < n; i++)
if(s < x[i].b)
{
ok = 0;
break;
}
else s += x[i].a;
if(ok) printf("YES\n");
else printf("NO\n");
}
return 0;
}