Getting wrong output

I am solving E-Knapsack 2 of atcoder dp contenst.
This is my solution… i have come up with…


But this is showing wrong answer, could you tell me where i am failing.
This is a top-down approach.
Thanks

hello @ashishnnnnn
what is ur dp state storing ?

dp[i][j] state is storing …mimimum weight required to get value ‘j’ having 0 to i size array.

this line may overflow , because solve is returning INT_MAX and INT_MAX + somthing overrflow for int.
so use long long and then try


It is showing segmentation fault…
Don’t know why…

Got Accepted…
Again a liitle mistake in indexing,


Thanks