代码
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Arrays;
import java.util.Comparator;
public class Main {
static StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
public static void main(String[]args) {
int n = readInt(); //苹果数
int s = readInt(); //力气大小
int a = readInt(); // 椅子高度
int b = readInt(); // 手伸直的长度
int xy[][] = new int[n][2];
for(int i = 0;i < n;i ++) {
for(int j = 0;j < 2;j ++) {
xy[i][j] = readInt();
}
}
Arrays.sort(xy,new Comparator<int[]> () {
public int compare(int[]e1,int[]e2) {
if(e1[1] == e2[1]) {
return e2[0]-e1[0]; // 对第一列元素进行升序排序
}
return e1[1]-e2[1]; // 对第二列元素进行升序排序
}
});
int reach = a + b;
long ans = 0;
for(int i = 0;i < n;i ++) {
if(reach >= xy[i][0]) {
s -= xy[i][1];
if(s >= 0) {
ans ++;
}
}
}
System.out.println(ans);
}
public static int readInt() {
try {
st.nextToken();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return (int)(st.nval);
}
}