Using the help of an evil Black Mesa scientist, Wheatly came back from outer space, and has retaken the Aperture Science testing facility. This time, he will make the testing harder for you and Caroline.
Just like the last time, you're going to be completing a series of portal-based puzzles to keep Wheatly entertained while Caroline find the corrupted cores so you can detach Wheatly from the system. Each puzzle has a duration $t$ and a reward $r$. If you choose to complete a certain puzzle, Wheatly's satisfaction will first decrease by $t$, then increase by $r$. If Wheatly's satisfaction becomes less than or equal to zero at any point during the testing, he will get very angry and blow up the entire Aperture Science testing facility.
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$, Wheatly's initial satisfaction ($1 \leq s \leq 10^6$).
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^6$).
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^6$).
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
|
3 Copy
|
4 12 20 20 20 20 0 0 0 0 Copy
|
0 Copy
|