Problem: There are N children, numbered 1, 2, ..., N.  Snuke has decided to distribute x sweets among them. He needs to give out all the x sweets, but some of the children may get zero sweets.  For each i (1 \leq i \leq N), Child i will be _happy_ if he/she gets exactly a_i sweets. Snuke is trying to maximize the number of happy children by optimally distributing the sweets. Find the maximum possible number of happy children.

Submission attempts (in order):
n, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
count = 0

try:
    while x >= a[0]:
        x -= a.pop(0)
        count += 1
except IndexError:
    pass

print(count)

n, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
count = 0

for i in a:
    if x >= i:
        x -= i
        count += 1
    else:
        pass
        
print(count)

n, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
count = 0

while x > min(a):
for i in a:
    if x >= i:
        x -= i
        count += 1
    else:
        pass
        
print(count)

n, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
count = 0

for i in a:
    if x >= min(a) and x >= i:
        x -= i
        count += 1
    else:
        pass
        
print(count)

n, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
count = 0

for i in a:
    if x >= i:
        x -= i
        count += 1
    else:
        pass
        
print(count)

n, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
count = 0

while x >= min(a):
    for i in a:
        if x >= i:
            x -= i
            count += 1
        else:
            pass
        
print(count)

n, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
count = 0

for i in a:
    if x >= i:
        x -= i
        count += 1
        
print(count)

n, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
count = 0

while x > min(a):
    for i in a:
        if x >= i:
            x -= i
            count += 1
        else:
            pass
        
print(count)

n, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
count = 0

for i in a:
    if x >= min(a) or x >= i:
        x -= i
        count += 1
    else:
        pass
        
print(count)

n, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
count = 0

while x > min(a):
    pass
for i in a:
    if x >= i:
        x -= i
        count += 1
    else:
        pass
        
print(count)

n, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
count = 0

for i in a:
    if x >= a[min]:
        x -= i
        count += 1
    else:
        pass
        
print(count)

n, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
count = 0

for i in a:
    if x >= i:
        x -= i
        count += 1
    else:
        pass
        
print(count)

N, x = map(int, input().split())
a = sorted(map(int, input().split()))
cnt = 0
for i in a:
    if x >= i:
        cnt += 1
        x -= i
    else:
        break
else:
    if x > 0:
        cnt -= 1
print(cnt)

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Time Limit Exceeded

Runtime Error

Wrong Answer

Accepted