fork download
  1. import java.io.*;
  2. import java.util.Arrays;
  3. class paying
  4. {
  5. public static void main(String args[])throws IOException
  6. {
  7. //System.out.println("test");
  8. int test=Integer.parseInt(br.readLine());
  9. while(test-->0)
  10. {
  11. String s[]=br.readLine().split(" ");
  12. int n=Integer.parseInt(s[0]);
  13. int m=Integer.parseInt(s[1]);
  14. int a[]=new int[n];
  15. for(int i=0;i<n;i++)
  16. {
  17. a[i]=Integer.parseInt(br.readLine());
  18. }
  19. Arrays.sort(a);
  20. for(int i=n-1;i>=0;i--)
  21. {
  22. if(m>=a[i])
  23. {
  24. m=m-a[i];
  25. }
  26. }
  27. if(m==0)
  28. System.out.println("Yes");
  29. else
  30. System.out.println("No");
  31. }
  32. }
  33. }
Success #stdin #stdout 0.1s 320256KB
stdin
1
5 10
2
2
3
4
5
stdout
No