372 传统题

[ABC364E] 最大贪吃鬼 (Maximum Glutton)

时间限制
3000ms
内存限制
1024MiB
登顶 / 尝试
1/ 1
难度
5
    上传者 标签AtCoderABC364提高-动态规划背包

[ABC364E] 最大贪吃鬼 (Maximum Glutton)

Score : 475475 points

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

  • 1≤N≤801 \leq N \leq 80

  • 1≤Ai,Bi≤100001 \leq A_i, B_i \leq 10000

  • 1≤X,Y≤100001 \leq X, Y \leq 10000

  • All input values are integers.

Input

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

$N$ $X$ $Y$
$A_1$ $B_1$
$A_2$ $B_2$
$\vdots$
$A_N$ $B_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