#include
#include<stdlib.h>
#include
#include
#include
#include<stdlib.h>
using namespace std;
void check(int *input, long int m, long int size)
{
long int n=(pow(2.0,size)-1);
long int j=n;
long int flag=0;
while(j>0)
{
n=j;
long int sum=0;
long int i=size-1;
flag=0;
while(n>0)
{
if(n%2)
sum+=input[i];
i-=1;
n/=2;
if(sum==m)
{
flag=1;
break;
}
}
if(flag==1)
{
cout<<“Yes”;
break;
}
j-=1;
}
if(flag==0)
cout<<“No”;
}
int main ()
{
long int T,M,N;
int input;
cin>>T;
while(T)
{
cin>>N >> M;
input=(int )malloc(sizeof(int)*N);
for(int i=0; i<N; i++)
cin>>input[i];
check(input,M,N);
T-=1;
}
return 0;
}
I dont know why but WA is showing up. I have tried many test cases and end cases . Please help.!