WA on MARCHA1, passes all test cases

import java.util.;
import java.lang.
;

class MARCHA1{
    static int getMaxIndex(int[] arr, int thresh){
	int max = 0;
	int index = 0;
	for(int i=0;i<arr.length;i++){
	    if(arr[i] > max && arr[i]<=thresh){
		max = arr[i];
		index = i;
	    }
	}
	return index;
    }
    public static void main(String[] args){
	Scanner scanner = new Scanner(System.in);
	int t = scanner.nextInt();
	while(t-- > 0){
	    int n = scanner.nextInt();
	    int m = scanner.nextInt();
	    int[] cash = new int[n];
	    for(int i=0;i<n;i++){
		cash[i] = scanner.nextInt();
	    }
	    //System.out.println("Array has values");
	    //System.out.println("M is " + m);
	    int sum = 0;
	    while(sum < m){
		int index = getMaxIndex(cash, m-sum);
		//System.out.println("Index returned is.. " + index);
		if(cash[index] == 0){
		    System.out.println("No");
		    return;
		}
		sum += cash[index];
		cash[index] = 0;
		//System.out.println("Now the sum is.. " + sum);
	    }
	    //System.out.println("Final Sum is.. " + sum);
	    if(sum==m){
		System.out.println("Yes");
	    }
	    else{
		System.out.println("No");
	    }
	}
    }
}

This code passes all test cases and also the test cases. Algorithm is to find maximum possible note between m and current sum - m, where current sum is the sum of notes found till now. Please help. Thanks in advance.

Input

1

4 10

5

2

4

4

Your Code Output:

No

Correct Output:

Yes