#P1478. 陶陶摘苹果(升级版)

陶陶摘苹果(升级版)

Description

It is autumn again, and the apple tree at TaoTao’s home has borne nn fruits. TaoTao goes to pick apples; this time he has a chair of height aa centimeters. When he cannot reach with his hand, he will stand on the chair and try again.

Different from the first problem of NOIp 2005 Junior: after moving the stool earlier, TaoTao has only ss strength left. Of course, each time he picks an apple, it costs some strength. TaoTao wants to know the maximum number of apples he can pick before s<0s < 0.

Now you are given the heights above the ground of the nn apples xix_i, the chair height aa, TaoTao’s maximum reach bb, his remaining strength ss, and the strength needed to pick each apple yiy_i. Find the maximum number of apples TaoTao can pick.

Input Format

Line 1: two numbers, the number of apples nn and the strength ss.

Line 2: two numbers, the chair height aa and TaoTao’s maximum reach bb.

Lines 3 to 3+n13 + n - 1: each line contains two numbers, the apple height xix_i and the strength needed to pick this apple yiy_i.

Output Format

Output a single integer, the maximum number of apples that TaoTao can pick.

8 15
20 130
120 3
150 2
110 7
180 1
50 8
200 0
140 3
120 2
4

Hint

For 100%100\% of the testdata, n5000n \leq 5000, a50a \leq 50, b200b \leq 200, s1000s \leq 1000, xi280x_i \leq 280, yi100y_i \leq 100.

Translated by ChatGPT 5