https://www.codechef.com/MARCH09/problems/A1

`
#include
#include
using namespace std;
int main()
{
unsigned short t;
cin>>t;
while(t–)
{
unsigned short n,d,flag=0;
cin>>n>>d;
int a[n]={0};
for(int i=0;i<n;i++)
{
cin>>a[i];
if(a[i]>1000)
a[i]=0;
}
if(n<20)
sort(a,a+n);
else
sort(a,a+20);
int pos=0;
for(int i=0;i<n;i++)
{

		if(d>=a[i])
		{

			pos=i;
		}
	}
	int sum=0;
	for(int i=pos;i>-1;i--)
	{
	    sum=a[i];
	    for(int j=i-1;j>-1;j--)
	    {
	        if(sum+a[j]<d)
		{
			sum+=a[j];
		}else if(sum+a[j]==d||sum==d)
		{
			// cout<<"sum is "<<sum;
			flag=1;
			break;
		}
	    }
	    if(flag==1)
	    break;
	 
	}
	if (flag==1)
	{
		cout<<"Yes\n";
	}else
	cout<<"No\n";
}
return 0;

}
`

can you format the entire code or share a link to your submission

1 Like

https://www.codechef.com/viewsolution/34217255

Your approach seems incorrect. It is a standard DP problem.
Look here.