Colourful knapsack problem

why getting wrong answer. What is the right code??

import java.util.HashMap;
import java.util.Scanner;

public class Main {
public static void main(String agrs[]){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int val=sc.nextInt();
int a[]=new int[n];
int b[]=new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
for(int i=0;i<n;i++){
b[i]=sc.nextInt();
}
int k=fun(a,b,0,0,m,val,new HashMap<>(),new int[m+1][val+1]);
if(k==100000)
System.out.println(-1);
else
System.out.println(k);
}
public static int fun(int a[], int b[], int i, int m,int jaj, int val, HashMap<Integer,Integer> visited,int dp[][]){
if(visited.size()==jaj && i>=a.length )
return val;
if(i>=a.length)
return 1000000;
int x=100000,y=100000,z=100000;
if(dp[m][val]!=0)
return dp[m][val];
if(a[i]<=val){
if(!visited.containsKey(b[i])){
visited.put(b[i],1);
x=fun(a,b,i+1,m+1,jaj,val-a[i],visited,dp);
visited.remove(b[i]);
}
//z=fun(a,b,i+1,m,jaj,val,visited,dp);
}
y=fun(a,b,i+1,m,jaj,val,visited,dp);
return dp[m][val]=Math.min(x,Math.min(y,z));

}

}