Minimum money needed

What is wrong with my code it is not passing even one testcase
import java.util.*;
public class Main {
static int inf=1000000009;
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int w=sc.nextInt();
int val[]=new int[n];
for(int i=0;i<n;i++)
val[i]=sc.nextInt();

   int dp[][]=new int[n+1][w+1];
   for(int i[] : dp)
   Arrays.fill(i,-1);
  int ans=Solve(val,n,w,dp);
  System.out.println(ans==inf?-1: ans);
}
public static int Solve(int val[],int n,int w,int dp[][])
{
	if(w==0)
	return 0;

    if(n==0)
	return inf;

	if(dp[n][w]!=-1)
	return dp[n][w];

   if(w>=n && val[n-1]!=-1)
   { 
	   int ans=Solve(val,n,w-n,dp);
	   if(ans!=inf)
	   ans+=val[n-1];
	  return  dp[n][w]=Math.min(ans,Solve(val,n-1,w,dp));
   }  
   else
   return dp[n][w]=Solve(val,n-1,w,dp);

}

}

hi @hemanthswarna1506
you have to read the question carefully.
Input Format

First line of input contains two space separated integers N and W, the number of friend he has and the amount of Oranges in kilograms which he should buy.

The second line contains W space separated integers in which the i^th^ integer specifies the price of a ‘i’kg apple packet. A value of -1 denotes that the corresponding packet is unavailable

here is your correct code

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.