Help with code needed

cant figure out whats wrong with the code pls look into it
not passing any testcase.

@pradhumangupta99 hey runtime rror is given by compiler as you have not checked: whether j-w[i-1] is greater than 0 or not if greater than only use it as dp index else not.

i am getting wrong answer on all cases and according to me the code is working fine.

even the hint of the question suggest similar logic

@pradhumangupta99 hey bro youyr logic is fine but check the condition which I have mentioned above or you can check this code for refernce:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.