meetinthemiddle(2)

PHOTO EMBED

Fri Nov 06 2020 15:00:33 GMT+0000 (UTC)

Saved by @Shami_Al #c++

/**
   SHAMI AL BASHAR PROTHOY
   PRESIDENCY INTERNATIONAL SCHOOL
**/

#include <bits/stdc++.h>
using namespace std;
#define csee "Case "<<cs<<": "
typedef long long ll;
typedef long double ld;
#define B begin()
#define E end()
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define ins insert
#define vi vector
#define ins insert
const ld pi=2*acos(0.0);
ll T,cs=1;
struct pt
{
    ll x,y,t;
};
/**
THINK TWICE,
      CODE ONCE
**/
void show(vi<ll>&v)
{
    for(auto it:v)cout<<it<<' ';
    cout<<"\n";
}
vi<ll> filsub(vi<ll>v)
{
    vi<ll>temp;
    ll i,j,n=v.size(),sum;
    for(i=0;i<(1<<n);i++)
    {
        sum=0;
        for(j=0;j<n;j++)
        {
            if(i&(1<<j))
                sum+=v[j];
        }
        temp.pb(sum);
    }
    return temp;
}
void sol(ll cs)
{
    vi<ll>v,va,vb;
    ll n,i,a,k;
    cin>>n>>k;
    for(i=0;i<n;i++)cin>>a,v.pb(a);
    va.assign(v.B,v.E-n/2);
    vb.assign(v.B+(n+1)/2,v.E);
    sort(va.B,va.E);
    sort(vb.B,vb.E);
    va=filsub(va);
    vb=filsub(vb);
    bool bl=false;
    for(i=0;i<va.size();i++)
    {
        if(binary_search(vb.B,vb.E,k-va[i]))
        {
            bl=true;
            break;
        }
    }
    cout<<csee<<((bl)?"Yes":"No")<<"\n";
}
//CODE
int main()
{
    //freopen("inp.txt","r",stdin)
    scanf("%lld",&T);
    while(T--)
        sol(cs++);
    return 0;
}
content_copyCOPY