WA in MARCHA1?

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();
	}
}
1 Like
if(n<=20 && m<=1000)

Muggers can ask any amount of money. No such cosntraint on m. Try resubmitting after removing all these unnecessary constraint checks.

Your code gives NO OUTPUT on this test case, hence getting WA-

Input
1
3 1
2
2
2

Initialize answer string to No.

1 Like

Thank you so much. It worked.