My issue
I am able to crack the sample test case, but I am shown a runtime error in the test cases, please help me out:)
My code
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
int t,n;
long m;
Scanner sc=new Scanner(System.in);
t=sc.nextInt();
while(t-->0){
n=sc.nextInt();
m=sc.nextLong();
int p[]= new int[n];
for(int i=0;i<n;i++) p[i]=sc.nextInt();
Arrays.sort(p);
long sum=0,count=0;
for(int i=p.length-1;i>=0;i--){
if(sum+p[i]<m){
sum+=p[i];
count++;
}
else if(sum+p[i]==m){
sum+=p[i];
count++;
break;
}
}
if(sum<m) count=-1;
System.out.println(count);
}
}
}
Problem Link: Andrew and the Meatballs Practice Coding Problem - CodeChef