paying up: wrong answer

#include<stdio.h>
int b[20];
int main()
{
int i,j,t,n,m,a,s=1,k;
scanf("%d",&t);
while(t–)
{
scanf("%d%d",&n,&m);
i=0,j=0;
while(i<n)
{
scanf("%d",&a);
if(a<=m)
{
b[j]=a;
++j;
}
++i;
}
i=0,a=j,j=0;
while(i<a)
{
s=m-b[i];
j=0;
while(j<a)
{ if(i==j);

			    else if(s==0)
			    goto x;
			    
				else 
				{k=0;
				while(k<a)
				{
					if(s==b[k])
					{
						s=0;
						goto x;
					}
					++k;
				}	
				if(b[j]<=s&&s>0)
				s=s-b[j];
			    }
				++j;
			    
			}
			++i;
		}
	x:	
    if(s==0)
	printf("Yes\n");
	else
	printf("No\n");	
	}
}

chopra…lge reh…khud try kr…ho jayega…

3 Likes

aur go to ke bina try kr…
hint…use recursion…

1 Like