Minimum money needed------

why my code is giving wrong answer
link:-

Weight of ith package is i not 1.
Line 17 and 30. Please fix them.


still not printing anything

You’re sending value of N incorrectly to function. Send n-1. Also arr[i] = i+1.

still not giving correct ans

Hi @riprogerdep

I have made few minor changes in your code. It works now.

Hope it Hepls.

link :- https://ide.codingblocks.com/s/195486

plz tell where my code is going wrong i have tried many times

plz reply…

Hey @riprogerdep
Sorry for the delay
Please replace line 15 with this
int a=INT_MAX,b=INT_MAX;

bro still solution is not getting accepted plz once you submit and when it fully correct then tell me the changes because i have been debugging it since long time …my this question is pending since 15 days you can see it.

@riprogerdep

Please close the doubt if your issue is resolved

line no. 41 par cout<<min_money(w-1,w)<<’\n’; why passed w-1 instead of n .
and for base case
if(n==-1){
return 1000;
}
if n==0 means no item then to make any sum is infinite INT_MAX then why you r doing this for n=-1

@riprogerdep
N is actually useless in this question. Input is W elements and we need to make weight of basket equal to W as well.
I passed (w-1,w) to min_money , I’m using 0 based indexing so -1 means I’ve gone beyond first element

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.