fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Codechef
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. // your code goes here
  10. Scanner sc=new Scanner(System.in);
  11. int t=sc.nextInt();
  12. while(t-->0){
  13. int n=sc.nextInt();
  14. int y=sc.nextInt();
  15. int [] ar=new int[n];
  16. for(int i=0;i<n;i++){
  17. ar[i]=sc.nextInt();
  18. }
  19. boolean ok=solve(ar,y);
  20. System.out.println(ok);
  21. }
  22. sc.close();
  23. }
  24.  
  25. public static boolean solve(int []ar,int y){
  26. boolean [][] dp=new boolean[ar.length+1][y+1];
  27. dp[0][0]=true;
  28. for(int i=1;i<=ar.length;i++){
  29. for(int j=0;j<=y;j++){
  30. if(j>=ar[i-1]&& dp[i-1][j-ar[i-1]]==true){
  31. dp[i][j]=true;
  32. }else if(dp[i-1][j]==true){
  33. dp[i][j]=true;
  34. }
  35. }
  36. }
  37. return dp[ar.length][y];
  38. }
  39. }
  40.  
Success #stdin #stdout 0.18s 54480KB
stdin
2
5 9
6 3 6 5 1
5 50
6 3 6 5 1
stdout
true
false