My issue
t = int(input())
for _ in range(t):
n, m = map(int, input().split())
idli_list = list(map(int, input().split()))
r ,count = m ,0
idli_list = sorted(idli_list,reverse = True)
for packet in idli_list:
if r>0 and packet<=r:
r = r - packet
count = count + 1
if count >0:
print(count)
else:
print(-1)
please debug my answer
and let me know my mistake
My code
t = int(input())
for _ in range(t):
n, m = map(int, input().split())
idli_list = list(map(int, input().split()))
r ,count = m ,0
idli_list = sorted(idli_list,reverse = True)
for packet in idli_list:
if r>0 and packet<=r:
r = r - packet
count = count + 1
if count >0:
print(count)
else:
print(-1)
Learning course: Kalasalingam Academy of Research and Education
Problem Link: CodeChef: Practical coding for everyone