P1478
#include<bits/stdc++.h>
using namespace std;
struct apple{
int high;
int l;
};
bool cmp(apple a,apple b){
return a.l<b.l;
}
int main(){
apple applec[100000];
int a,s,c,b,sum=0,tmp=0;
cin>>a>>s>>c>>b;
b+=c;
sum=b;
for(int i=0;i<=a-1;i++){
cin>>applec[i].high;
cin>>applec[i].l;
}
sort(applec,applec+a,cmp);
for(int i=0;i<a;++i){
if(applec[i].l<=s&&applec[i].high<=b){
sum-applec[i].l;
tmp++;
}
}
cout<<tmp;
}