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()

b = []
for i in range(N):
    b.append(0)
    
c = 0

d = []
for i in range(N):
    d.append(0)


for i in range(N):
    for j in range(i+1):
        d[i] += a[j]
        b[i] = d[i]
for i in range(N):
    if b[i] <= X:
        c += 1
print(c)

N,X = map(int,input().split())
a = list(map(int,input().split()))
a.sort()

b = []
for i in range(N):
    b.append(0)
    
c = 0

for i in range(N):
    for j in range(i+1):
        b[i] += a[j]

for i in range(N):
    if b[i] <= X:
        c += 1
print(c)

N,X = map(int,input().split())
a = list(map(int,input().split()))
a.sort()

b = []
for i in range(N):
    b.append(i)
c = 0
for i in range(N):
    b[i] = 0
    for i in range(N):
        b[i] += a[i]
for i in range(N):
    if b[i] <= X:
        c += 1
print(c)

N,X = map(int,input().split())
a = list(map(int,input().split()))
a.sort()

b = []
for i in range(N):
    b.append(0)
    
c = 0

for i in range(N):
    for j in range(i+1):
        b[i] += a[j]

for k in range(N):
    if b[k] <= X:
        c += 1
print(c)

N,X = map(int,input().split())
a = list(map(int,input().split()))
a.sort()

b = []
for _ in range(N):
    b.append(0)
    
c = 0

for i in range(N):
    for j in range(i+1):
        b[i] += a[j]

for k in range(N):
    if b[k] <= X:
        c += 1
if b[-1] > X:
    c -= 1
print(c)

N,X = map(int,input().split())
a = list(map(int,input().split()))
a.sort()

b = []
for _ in range(N):
    b.append(0)
    
c = 0

for i in range(N):
    for j in range(i+1):
        b[i] += a[j]

for k in range(N):
    if b[k] <= X:
        c += 1
    else:break
print(c)

N,X = map(int,input().split())
a = list(map(int,input().split()))
a.sort()

b = []
for _ in range(N):
    b.append(0)
    
c = 0

for i in range(N):
    for j in range(i+1):
        b[i] += a[j]

for k in range(N):
    if b[k] <= X:
        c += 1
print(c)

N,X = map(int,input().split())
a = list(map(int,input().split()))
a.sort()

b = []
for i in range(N):
    b.append(0)
    
c = 0

d = []
for i in range(N):
    d.append(0)


for i in range(N):
    b[i] = d[i]
    for j in range(i+1):
        d[i] += a[j]
for i in range(N):
    if b[i] <= X:
        c += 1
print(c)

N,X = map(int,input().split())
a = list(map(int,input().split()))
a.sort()

b = []
for i in range(N):
    b.append(i)
c = 0
d = []
for i in range(N):
    d.append(i)
for i in range(N):
    b[i] = d
    for j in range(N):
        d[j] += a[j]
for i in range(N):
    if b[i] <= X:
        c += 1
print(c)

N,X = map(int,input().split())
a = list(map(int,input().split()))
a.sort()

b = []
for _ in range(N):
    b.append(0)
    
c = 0

for i in range(N):
    for j in range(i+1):
        b[i] += a[j]

for k in range(N-1):
    if b[k] <= X:
        c += 1
if b[N-1] == X:
    c += 1
print(c)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Accepted