Paying Up ! Find the error

I am unable to get why my algo fails in the last sample test case of the problem
Here is my code :

#include<cstdio>
#include<algorithm>

using namespace std ; 

int main ()
{
	int m , i , t , n , arr[22] , j   ; 
	scanf ("%d",&t) ; 
	while (t--)
	{
		scanf ("%d %d",&n , &m) ; 
		for (i = 0 ; i<n ; i ++)
			scanf ("%d",&arr[i]) ; 
		sort (arr , arr+n )  ; 

		printf ("AFter Sorting Output of the array\n")  ; 
		for (j = 0 ;  j<n ; j++)
			printf ("arr[%d] = %d\n",j,arr[j])  ; 		
		
		for (i = n ; i>=0 ; i--)
		{
			if (arr[i] <= m)
			{
				m = m - arr[i] ; 
				if (m == 0 )
					break ; 
			}
		}

		if (m == 0 ) 
			printf ("Yes\n")  ; 
		else 
			printf ("No\n")  ; 
	} 
return 0 ; 
}

If there is some mistake in this algo please sugggest me some other algo …THANKS A LOT !!!

Why are you printing all this extras?

printf ("AFter Sorting Output of the array\n")  ; 
for (j = 0 ;  j<n ; j++)
    printf ("arr[%d] = %d\n",j,arr[j])  ;

In the output do not print any extra data other than as mentioned in Output Format. For this question, you just need to print Yes or No.

For each test case output a single line with the word 'Yes' if there is a subset of your banknotes that sums to m, and 'No' otherwise.

Also you are storing values in array from a[0] to a[n-1] but you are accessing a[n] later in your code without initiating. This would result in wrong answer as it may take a garbage value or previous value in a[n].

Your algo doesn’t work for cases like

5 12
2
3
4
5
7

Answer should be Yes but your code gives No. I hope this Editorial would help you.

Thanks @vinayawsm for the test cases…and i was printing that for the check itself