fork download
  1. #include<iostream>
  2. #include<bits/stdc++.h>
  3. #define ll long long
  4. using namespace std;
  5.  
  6. int main(){
  7. int t;cin>>t;
  8. while(t--){
  9. int n,s;cin>>n>>s;
  10. vector<int>a(n);
  11. for(int i=0;i<n;i++) cin>>a[i];
  12. vector<bool>dp(s+1,false);
  13. dp[0]=true;
  14. for(int i=0;i<n;i++){
  15. for(int j=s;j>=a[i];j--){
  16. if(dp[j-a[i]]==true){
  17. dp[j]=true;
  18. }
  19. }
  20. }
  21. if(dp[s]) cout<<"YES";
  22. else cout<<"NO";
  23. cout<<endl;
  24. }
  25. }
Success #stdin #stdout 0.01s 5296KB
stdin
2

5 6
1 2 4 3 5

10 15

2 2 2 2 2 2 2 2 2 2
stdout
YES
NO