zhuangmy_ @ 2023-10-25 16:58:03
代码:
#include <iostream>
#include <algorithm>
using namespace std;
struct st
{
int x, y;
};
bool cmp(st a, st b)
{
return a.y < b.y;
}
st c[5001];
int main()
{
int n, s, cnt = 0;
cin >> n >> s;
int a, b;
cin >> a >> b;
for (int i = 1; i <= n; ++i)
{
cin >> c[i].x >> c[i].y;
}
sort(c + 1, c + n + 1, cmp);
for (int i = 1; i <= n; ++i)
{
if (s - c[i].y < 0 || a + b < c[i].x)
{
break;
}
cnt++;
s -= c[i].y;
}
cout << cnt << endl;
return 0;
}