#abc364e. E - Maximum Glutton

E - Maximum Glutton

Score : 475475 points

问题陈述

高桥为Snuke准备了NN道菜。这些菜从11编号到NN,第ii道菜有甜度AiA_i咸度BiB_i

高桥可以随意安排这些菜的顺序。Snuke将按照安排的顺序吃菜,但如果在任何时候他吃过的菜的总甜度超过XX或总咸度超过YY,他将不再吃任何菜。

高桥希望Snuke尽可能多吃菜。如果高桥最优地安排菜,找出Snuke将吃的最大菜数。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

Takahashi has prepared NN dishes for Snuke. The dishes are numbered from 11 to NN, and dish ii has a sweetness of AiA_i and a saltiness of BiB_i.

Takahashi can arrange these dishes in any order he likes. Snuke will eat the dishes in the order they are arranged, but if at any point the total sweetness of the dishes he has eaten so far exceeds XX or the total saltiness exceeds YY, he will not eat any further dishes.

Takahashi wants Snuke to eat as many dishes as possible. Find the maximum number of dishes Snuke will eat if Takahashi arranges the dishes optimally.

Constraints

  • 1N801 \leq N \leq 80
  • 1Ai,Bi100001 \leq A_i, B_i \leq 10000
  • 1X,Y100001 \leq X, Y \leq 10000
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN XX YY

A1A_1 B1B_1

A2A_2 B2B_2

\vdots

ANA_N BNB_N

Output

Print the answer as an integer.

Sample Input 1

4 8 4
1 5
3 2
4 1
5 3

Sample Output 1

3

Consider the scenario where Takahashi arranges the dishes in the order 2,3,1,42, 3, 1, 4.

  • First, Snuke eats dish 22. The total sweetness so far is 33, and the total saltiness is 22.
  • Next, Snuke eats dish 33. The total sweetness so far is 77, and the total saltiness is 33.
  • Next, Snuke eats dish 11. The total sweetness so far is 88, and the total saltiness is 88.
  • The total saltiness has exceeded Y=4Y=4, so Snuke will not eat any further dishes.

Thus, in this arrangement, Snuke will eat three dishes.

No matter how Takahashi arranges the dishes, Snuke will not eat all four dishes, so the answer is 33.

Sample Input 2

2 1 1
3 2
3 2

Sample Output 2

1

Sample Input 3

2 100 100
3 2
3 2

Sample Output 3

2

Sample Input 4

6 364 463
230 381
154 200
328 407
339 94
193 10
115 309

Sample Output 4

3
}