#abc364e. E - Maximum Glutton
E - Maximum Glutton
Score : points
问题陈述
高桥为Snuke准备了道菜。这些菜从编号到,第道菜有甜度和咸度。
高桥可以随意安排这些菜的顺序。Snuke将按照安排的顺序吃菜,但如果在任何时候他吃过的菜的总甜度超过或总咸度超过,他将不再吃任何菜。
高桥希望Snuke尽可能多吃菜。如果高桥最优地安排菜,找出Snuke将吃的最大菜数。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
Takahashi has prepared dishes for Snuke. The dishes are numbered from to , and dish has a sweetness of and a saltiness of .
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 or the total saltiness exceeds , 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
- All input values are integers.
Input
The input is given from Standard Input in the following format:
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 .
- First, Snuke eats dish . The total sweetness so far is , and the total saltiness is .
- Next, Snuke eats dish . The total sweetness so far is , and the total saltiness is .
- Next, Snuke eats dish . The total sweetness so far is , and the total saltiness is .
- The total saltiness has exceeded , 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 .
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