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()))
count = 0


a.sort(reverse=False)
for i in range(N):
    if x >= a[i]:
        count += 1
        x -= a[i]
    else:
        break
    print(count)

if (x!=0)and(count == N):
    count -= 1
    print(count)

N,x = map(int,input().split())
a = list(map(int,input().split()))
count = 0

sort_a = sorted(a)

for i in range(len(a)):
    if x >= sort_a[i]:
        count += 1
        x -= sort_a[i]
        continue
    else:
        continue
    break
print(count)

N,x = map(int,input().split())
a=[int(input()) for i in range(N)]
# a = list(map(int,input().split()))
count = 0

sort_a = sorted(a)

for i in range(len(a)):
    if x >= sort_a[i]:
        count += 1
        x -= sort_a[i]
        continue
    break
print(count)

N,x = map(int,input().split())

a = list(map(int,input().split()))
count = 0

sort_a = sorted(a)

for i in range(len(N)):
    if x >= sort_a[i]:
        count += 1
        x -= sort_a[i]
    break
print(count)


for i in range(N):
    print(i)
    if x >= sort_a[i]:
        count += 1
        x -= sort_a[i]
        # print(x)
        continue
    break
print(count)

N,x = map(int,input().split())
a = list(map(int,input().split()))
count = 0

sort_a = sorted(a)
for i in range(len(a)):
    if x >= sort_a[i]:
        count += 1
        x -= sort_a[i]
        continue
    break
print(count)

N,x = map(int,input().split())

a = list(map(int,input().split()))
count = 0

sort_a = sorted(a)

for i in range(len(N)):
    if x >= sort_a[i]:
        count += 1
        x -= sort_a[i]
        print(x)
        continue
    break
print(count)


N,x = map(int,input().split())

a = list(map(int,input().split()))
count = 0

sort_a = sorted(a)

for i in range(N):
    print(i)
    if x >= sort_a[i]:
        count += 1
        x -= sort_a[i]
        # print(x)
        continue
    break
print(count)

N,x = map(int,input().split())

a = list(map(int,input().split()))
count = 0

sort_a = sorted(a)

for i in range(N):
    if x >= sort_a[i]:
        count += 1
        x -= sort_a[i]
    break
print(count)


N,x = map(int,input().split())
a = list(map(int,input().split()))
count = 0

sort_a = sorted(a)
for i in range(len(a)):
    if x > sort_a[i] and x == sort_a[i]:
        count += 1
        x -= sort_a[i]
        continue
    break
print(count)

N,x = map(int,input().split())
a = list(map(int,input().split()))
count = 0


a.sort(reverse=False)
for i in range(N):
    if x >= a[i]:
        count += 1
        x -= a[i]
    else:
        break

if (x!=0)and(count == N):
    count -= 1
print(count)


Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Accepted