Alice loves cookies. One day while wandering, she came across a cookie-world that has N cookies in it, numbered from 1 to N. Each cookie has is stored at height H. Initially, Alice's energy is K. and after eating a cookie with energy E her energy increases by E.
In each step, Alice can climb to a certain height and can eat a cookie and return to her original position, but climbing requires energy, and she can climb only if her energy K is greater than or equal to the height H.
Task
Determine the maximum number of cookies she can eat and the maximum energy she can attain after each step.
Example
N = 6
H=[6, 1, 3, 9, 15, 30]
E=[3, 5, 1, 2, 4, 3]
K=9 (initial energy)
Explanation
Cookies eaten by Alice to maximize her energy after each step are:
At first, Alice will eat cookie with energy 5 at a height of 1 and her energy increases to 9+5=14
Then Alice will eat cookie with energy 3 at a height of 6 and her energy increases to 14+3=17
Then Alice will eat cookie with energy 4 at a height of 15 and her energy increases to 17+ 4 = 21
Then Alice will eat cookie with energy 2 at a height of 9 and her energy increases to 21+2= 23
Then Alice will eat cookie with energy 1 at a height of 3 and her energy increases to 23+1=24
Alice will not be able to eat cookie at a height of 30
Can anyone share approach,thanks in advance.