https://www.luogu.org/problem/P1478
#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;
struct Item{
int xi;
int yi;
};
vector<Item> inputList;
//自定义排序函数
bool sortFun(const Item &p1, const Item &p2)
{
return p1.yi < p2.yi;//升序排列
}
int main(void)
{
int n,s,a,b;
cin>>n>>s>>a>>b;
for(int i = 0; i <n; i++)
{
Item o;
cin>>o.xi>>o.yi;
if(a+b >= o.xi)
inputList.push_back(o);
}
sort(inputList.begin(), inputList.end(), sortFun);
int iRet = 0;
vector<Item>::iterator iter = inputList.begin();
while (iter != inputList.end())
{
if (s>=iter->yi)
{
s -= iter->yi;
iRet++;
}
else
{
break;
}
iter++;
}
cout << iRet << endl;
return 0;
}