| SDU Open 2023 |
|---|
| Finished |
Egor is famous for his talent in sports programming, but few know that he is also an excellent cook who can easily prepare a variety of dishes.
He can be called CodeChef, given his impressive skills in solving FFT problems as well as in cooking steaks.
When the organizers of the SDU Open needed a chef to prepare steaks for the contest participants, they knew that Egor was the perfect person for the job.
Currently, there are $$$n$$$ participants in the queue, where the $$$i$$$-th participant must eat at least $$$a_i$$$ steaks to satisfy their hunger and eat $$$b_i$$$ steaks to feel full.
Although Egor is determined to make everyone full, the organizers want to save on food. To find a compromise, Egor was tasked with serving steaks in such a way that all participants are satisfied and at any given time, the number of full participants is not greater than the number of satisfied ones.
If it is known that Egor can prepare no more than $$$k$$$ steaks, what is the maximum number of participants he can make full?
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 10^5$$$, $$$1 \leq k \leq 10^9$$$) — the number of people in the queue and the maximum number of steaks Egor can prepare.
The next $$$n$$$ lines contain two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \leq a_i \lt b_i \leq 10^9$$$) — the number of steaks for the $$$i$$$-th participant to satisfy their hunger and feel full, respectively.
If it is impossible to satisfy the hunger of all participants, output -1. Otherwise, output a single integer — the maximum number of full participants.
3 2 1 2 1 3 1 4
-1
3 4 1 2 1 3 1 4
0
3 5 1 2 1 3 1 4
1
In the first example, Egor does not have enough steaks to satisfy the hunger of all participants ($$$2 \lt 3$$$).
In the second example, Egor can satisfy the first participant, but after that, the number of full participants will be greater than the number of satisfied ones, which goes against the compromise with the organizers. Therefore, Egor will have to not make the first participant full.
| Name |
|---|


