The code I’ve written passes all sample test cases and i tried with many other too, but it is sstill giving me wrong answer? Can someone please help?
import java.util.Scanner;
class marcha1
{
public static String to_pay(int a[],int n,int m)
{
if(m == 0)
return "Yes";
if(n<0)
return "No";
String ans =new String();
for(int i=n;i>=0;i--)
{
if(m-a[i]<0)
continue;
ans = to_pay(a,i-1,m-a[i]);
if(ans == "Yes")
break;
}
return ans;
}
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int t = input.nextInt();
if(t<=100)
while(t>0)
{
int n = input.nextInt();
int m = input.nextInt();
int[] a = new int[n];
if(n<=20 && m<=1000)
{
for(int i=0;i<n;i++)
a[i] = input.nextInt();
//Sorting
for(int i=0;i<n;i++)
for(int j=1;j<n-i;j++)
{
if(a[j-1]>a[j])
{
int temp = a[j];
a[j] = a[j-1];
a[j-1] = temp;
}
}
System.out.println(to_pay(a,n-1,m));
}
t--;
}
input.close();
}
}