here is my code,
import java.util.*;
class PintuAndFruits{
public static void main(String args[]) {
try{
Scanner scan = new Scanner(System.in);
int T=0,N=0,M=0;
T = scan.nextInt();
int fruit_type[];
int price[];
int total_price_fruits[];
boolean isValidFruit[];
int min =Integer.MAX_VALUE;
StringBuilder sb = new StringBuilder();
for(int j=0;j<T;j++){
N = scan.nextInt();
M = scan.nextInt();
fruit_type = new int [N];
price = new int[N];
total_price_fruits = new int[M+1];
isValidFruit = new boolean[M+1];
for(int i=0;i<N;i++){
fruit_type[i] = scan.nextInt();
isValidFruit[fruit_type[i]] = true;
}
for(int i=0;i<N;i++){
price[i] = scan.nextInt();
total_price_fruits[fruit_type[i]] += price[i];
}
for(int i=1;i<=M;i++){
if( min > total_price_fruits[i] && isValidFruit[i] == true){
min = total_price_fruits[i];
}
}
sb.append(min+"\n");
}
System.out.print(sb);
scan.close();
}
catch(Exception e){
}
}
}