#include<iostream>
#include<algorithm>
using namespace std;
int n, s, a, b;
struct Apple
{
int x, y;
}apple[5005];
bool compare(const Apple& a, const Apple& b)
{
return a.y < b.y;
}
int main()
{
int i, j;
Apple temp;
cin >> n >> s >> a >> b;
if (0 == s)
cout << '0';
else
{
for (i = 0, j = 0; i < n; i++)
{
cin >> temp.x >> temp.y;
if (temp.x <= a + b)
{
apple[j] = temp;
j++;
}
}
sort(apple, apple + j, compare);
for (i = 0; i < j && s >= 0; i++)
s -= apple[i].y;
if (0 == i)
cout << '0';
else
cout << i - 1;
}
return 0;
}
洛谷P1478 陶陶摘苹果(升级版)进阶解法
最新推荐文章于 2024-02-01 11:30:00 发布