Getting 0 all the time

plz help

@Akshay123
There are few mistake in your code

  1. number of input in second line in w not n. So change the size of val array to val[w]. Also change the condition in line 50 to i<w.
  2. Change line 53 to cout<<mincost(w,w,val,dp);
  3. Create dp array inside main() function. there is no sense of creating it globally and then passing it to function.
  4. Your code will always give 0 because see line 31. here n is directly reduce to n-1. Ultimately n become 0, in that case line 9 will be true and return 0. which will be minimum of all and hence final ans become 0. Inorder to correct it, move if(w==0) return 0; above if(n<=0) condition. And for if(n<=0) return INT_max;

Have done all changes but still getting WA at test case 1, but I am getting correct output in when running that test case elsewhere??? PLZ HELP

@Akshay123
One kind of orange can be used twice. So change line 26 to inc=val[n-1]+mincost(n,w-n,val,dp);
All testcase will pass

You got 100 points. Please mark it as resolved.