Wheatly has managed to take control of the Aperture Science testing facility, which is a huge problem since Wheatly is extremely stupid. You and your friend Caroline need to take it back, but to do that, you need to buy Caroline some time.
To do that, you're going to be completing a series of portal-based puzzles to keep Wheatly entertained. Each puzzle has a duration $t$ and a reward $r$. If you choose to complete a certain puzzle, Wheatly's satisfaction will decrease by $t$, then increase by $r$. If Wheatly's satisfaction becomes less than or equal to zero after completing the test, he will get very angry and blow up the entire Aperture Science testing facility (Note that he will not destroy the facility before the end of the test).
There are $n$ puzzles, and you're allowed to solve them in any order. Of course, you can't solve the same puzzle more than once, because Wheatly will be bored. Find the maximum number of puzzles that you can solve before Wheatly destroys the facility.
The first line of input contains two integers, $n$, the number of puzzles you have ($1 \leq n \leq 10^6$), and $s$, which represents Wheatly's initial satisfaction ($1 \leq s \leq 10^9$).
The second line contains $n$ space-separated integers $t_1,\space t_2,\space ...\space, t_n$, where $t_i$ is the time needed to complete the $i^{th}$ puzzle ($1 \leq t_i \leq 10^9$).
The third and last line contains $n$ space-separated integers $r_1,\space r_2,\space ...\space, r_n$, where $r_i$ is the satisfaction gained by completing the $i^{th}$ puzzle ($0 \leq r_i \leq 10^9$).
Output a single integer $k$, the maximum number of puzzles that you can solve.
Input | Output |
---|---|
6 6 3 5 8 22 36 21 6 5 6 12 2 1 Copy
|
4 Copy
|
4 12 20 20 20 20 0 0 0 0 Copy
|
1 Copy
|