# Paying up getting error even though i have ran all the test cases

testcases=int(input())
c=0
if testcases<1 or testcases>100:
c=1
while(c==0 and testcases):
p=0
t=0
n,m= [int(x) for x in input().split()]
a=[]
if n>20 or n<0:
t=1
if m>1000:
p=1
if t==0 and p==0:
for i in range(0,n):
k=int(input())
a.append(k)
a.sort()
for s in range(n-1,-1,-1):
if(m>=a[s]):
m=m-a[s]

``````   if m==0:
print('Yes')
else:
print('No')
testcases-=1``````

for s in range(n-1,-1,-1):
if(m>=a[s]):
m=m-a[s]

You are using greedy approach, which is wrong. Take this for example-

N=17
Money in wallet= {8,9,16}.

Your algo says no note exist, but a note exists.

Also, your wallet has 20 notes <=1000. So actually m can be greater than 1000 as m=sum of a subset of notes you have.

Thirdly, dont check for constraints. Constraints mean that â€śThis input file has values in between this rangeâ€ť

2 Likes

Thank you.

Please use â€śAccept Answerâ€ť feature (by clicking on tick in circle) instead of award points. Thats the way of giving karma here