http://www.luogu.org/problem/show?pid=1478
和05年的NOIP的原题一样水,直接贪心,不需要做01背包
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#define ms(i,j) memset(i,j, sizeof i);
using namespace std;
int y[5005];
int main()
{
int n,s,a,b;
scanf("%d%d%d%d", &n ,&s, &a ,&b);
int cnt = 0;
for (int i=1;i<=n;i++)
{
int xi,yi;
scanf("%d%d", &xi ,&yi);
if (a+b>=xi)
{
y[++cnt] = yi;
}
}
sort(y+1, y+1+cnt);
int tot = 0;
int ans = 0;
for (int i=1;i<=cnt;i++)
{
if (tot + y[i] <= s)
{tot += y[i]; ans++;}
else break;
}
printf("%d\n", ans);
return 0;
}