TnT/Multi_CodeNet4Repair huggingface dataset:
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 = (int(i) for i in input().split(' '))
a = [int(i) for i in input().split(' ')]

ch = 0 

while x != 0: 
    if x - a[i] < 0: 
        x = 0
    else:
        x -= a[i]
        ch += 1

print(ch)        
    
    

n, x = (int(i) for i in input().split(' '))
a = sorted([int(i) for i in input().split(' ')])

ch = 0 
s = 0
for i in range(n):
    if x < a[i]:
        x = 0
    elif x >= a[i]:
        x -= a[i]
        ch += 1
        
if x > 0:
    ch = ch -1

print(ch)

Verdicts: Runtime Error

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

def score(a, m, x):
    ans = x*(n+m)
    l = n//m
    for i in range(n):
        t = (n-1-i)//m
        if i < m:
            ans += ((t+2)**2) * a[i]
        else:
            ans += ((t+2)**2) * (a[i] - a[i-m])
    for i in range(m):
        ans += a[n-1-i]
    return ans
        
def search(left, right, l_score, r_score, a, x):
    tri = (right-left)//3
    u_score = score(a, left+tri, x)
    v_score = score(a, left+tri*2, x)
    if right-left <= 3:
        return min(u_score, v_score, l_score, r_score)
    elif l_score < u_score:
        return search(left, left+tri, l_score, u_score, a, x)
    elif r_score < v_score:
        return search(left+tri*2, right, v_score, r_score, a, x)
    elif u_score < v_score:
        return search(left, left+tri*2, l_score, v_score, a, x)
    else:
        return search(left+tri, right, u_score, r_score, a, x)
    
    
def sub_search(r, a, x):
    ans = score(a, r//2+1, x)
    #print(ans)
    for i in range(r//2):
        j = r//2 - i
        ddd = score(a, j, x)
        #print(ddd)
        if ddd <= ans:
            ans = ddd
        else:
            break
    return ans
    
    
#k = search(1, n, score(a, 1, x), score(a, n, x), a, x)
k = sub_search(n, a, x)
print(k)

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

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

a = sorted(a)
ans = 0
f = 1
for i in range(n):
    x -= a[i]
    if x<0:
        f = 0
        break
    ans += 1
    
if x != 0 and f == 1:
    ans -= 1
    
print(ans)


Verdicts: Wrong Answer

Accepted
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()
cnt=0
for i in range(n):
    if a[i]<=x:
        x-=a[i]
        cnt+=1
    else:
        break
print(cnt)


n,x=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*n
a.sort()
cnt=0
for i in range(n):
    if a[i]<=x:
        x-=a[i]
        if i==n-1 and x!=0:
            break
        cnt+=1
    else:
        break
print(cnt)


Verdicts: Wrong Answer

Accepted
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())
lst=sorted(list(map(int,input().split())))
ans=0
for i in range(1,n+1):
    if sum(lst[:i]) <= x:
        ans = len(lst[:i])
print(ans)

N,x=map(int,input().split())
A=sorted(list(map(int,input().split())))
a=[0]*N
a[0]=A[0]
for i in range(N-1):
    a[i+1]=a[i]+A[i+1]
ans=0
for i in a:
    if i<=x:
        ans+=1
print(ans if x<=a[-1] else ans-1)


Verdicts: Wrong Answer

Accepted
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):
def main():
    N, x = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    if sum(a) <= x:
        print(N)
        return
    for i in range(N):
        x -= a[i]
        if x < 0:
            break
    ans = i
    print(ans)

if __name__ == "__main__":
    main()


def main():
    N, x = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    if sum(a) == x:
        print(N)
        return
    for i in range(N):
        x -= a[i]
        if x < 0:
            break
    ans = i
    print(ans)

if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Accepted
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=sorted(list(map(int,input().split())))
c,i=0,0
while(i<n and x>0):
  if a[i]<=x:
    x-=a[i]
    c+=1
    i+=1
  else:
    break
print(c)

n,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
c,i=0,0
while(i<n and x>0):
  if a[i]<=x:
    x-=a[i]
    c+=1
    i+=1
  else:
    break
print(c)

n,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
c,i=0,0
while(i<n and x>0):
  if a[i]<=x:
    x-=a[i]
    c+=1
  else:
    break
  if i==n-1 and x!=0:
    c-=1
  i+=1
print(c)

Verdicts: Wrong Answer

Wrong Answer

Accepted
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()
sum = 0
count = 0
while True:
  if sum > x or len(a) == 0:
    break
  sum += a[0]
  count += 1
  del a[0]
print(count)

N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
sum = 0
count = 0
while True:
  sum += a[0]
  if sum > x:
    break
  count += 1
  del a[0]
  if len(a) == 0:
    break
print(count)

N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
sum = 0
count = 0
while True:
  sum += a[0]
  if sum > x or len(a) == 0:
    break
  count += 1
  del a[0]
print(count)

N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
sum = 0
count = 0
while True:
  sum += a[0]
  if sum > x:
    break
  count += 1
  del a[0]
  if len(a) == 0:
    break
if x > sum:
  print(count-1)
else:
  print(count)

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Accepted
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()
cnt = 0
su = 0
for i in range(N):
  if su + a[i] <= x:
    su += a[i]
    cnt += 1
  else:
    break
print(cnt)

N,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
if sum(a) < x:
  print(N-1)
  exit()
cnt = 0
su = 0
for i in range(N):
  if su + a[i] <= x:
    su += a[i]
    cnt += 1
  else:
    break
print(cnt)

Verdicts: Wrong Answer

Accepted
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()
for i in range(0, len(a), 1):
    x -= a[i]
    if x < 0:
        break
if i == len(a) - 1:
    print(i + 1)
else:
    print(i)


n, x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
for i in range(0, len(a), 1):
    x -= a[i]
    if x < 0:
        break
if x == 0:
    print(i + 1)
else:
    print(i)


Verdicts: Wrong Answer

Accepted
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())
fav = sorted(map(int, input().split()))
oura=[int()]*N

oura[0] = fav[0]
for i in range(len(fav)-1):
    oura[i+1] = oura[i] + fav[i+1]

print (oura)

sai = 0
for j in range(len(oura)):
    if oura[j] > x:
        sai = j
        break
    elif j != N-1:
        continue
    elif oura[N-1] == x:
        sai = N
    else:
        sai = N-1

print (sai)


N, x = map(int, input().split())
fav = sorted(map(int, input().split()))
oura=[int()]*N

oura[0] = fav[0]
for i in range(len(fav)-1):
    oura[i+1] = oura[i] + fav[i+1]

print (oura)

sai = 0
for j in range(len(oura)):
    if oura[j] > x:
        sai = j
        break
    elif j != N-1:
        continue
    elif oura[N-1] == x:
        sai = N
    else:
        sai = N-1

print (sai)


N, x = map(int, input().split())
fav = sorted(map(int, input().split()))
oura=[int()]*N

oura[0] = fav[0]
for i in range(len(fav)-1):
    oura[i+1] = oura[i] + fav[i+1]


sai = 0
for j in range(len(oura)):
    if oura[j] > x:
        sai = j
        break
    elif j != N-1:
        continue
    elif oura[N-1] == x:
        sai = N
    else:
        sai = N-1

print (sai)


Verdicts: Wrong Answer

Wrong Answer

Accepted
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 = sorted(map(int, input().split()))

c = 0
for ai in A:
    x -= ai
    if x<=0:
        break
    c+=1

print(c+1 if x==0 else c)

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

if sum(A) == x:
    print(N)

else:
    c = 0
    for ai in A:
        x -= ai
        if x <= 0:
            break
        c += 1

    print(c + 1 if x == 0 else c)

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

if sum(A) == x:
    print(x)

else:
    c = 0
    for ai in A:
        x -= ai
        if x <= 0:
            break
        c += 1

    print(c + 1 if x == 0 else c)

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

if sum(A) == x:
    print(N)

else:
    c = 0
    for ai in A:
        x -= ai
        if x <= 0:
            break
        c += 1

    if c == N:
        print(N - 1)
    else:
        print(c + 1 if x == 0 else c)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
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):
a, b = map(int, input().split())
child = sorted(list(map(int, input().split())))
count = 0
print(child)

for i in range(a - 1):
    if b >= child[i]:
        b -= i
        count += 1
if b == child[-1]:
        count += 1

print(count)

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

for i in range(a - 1):
    if b >= child[i]:
        b -= child[i]
        count += 1
if b == child[-1]:
        count += 1

print(count)

Verdicts: Wrong Answer

Accepted
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())
arr=list(map(int,input().split()))
arr=sorted(arr)
for i in range(n):
  if x-arr[i]>=0:
    x-=arr[i]
  else:
    print(i)
    break
else:
    print(n)

n,x=map(int,input().split())
arr=list(map(int,input().split()))
arr=sorted(arr)
for i in range(n):
  if x-arr[i]>=0:
    x-=arr[i]
  else:
    print(i)
    break
else:
  if x==0:
    print(n)
  else:
    print(n-1)

Verdicts: Wrong Answer

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

a_sum = [sum(a[:i+1]) for i in range(len(a))]

for i, item in enumerate(a_sum):
    if x < item:
        ans = i
        break
    elif x == item:
        ans = i+1
    elif x > item and i == len(a_sum):
        ans = i

print(ans)



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

ans = 0
a.sort()
a_sum = [sum(a[:i+1]) for i in range(len(a))]

for i, item in enumerate(a_sum):
    if x < item:
        ans = i
        break
    elif x == item:
        ans = i+1
    elif x > item and i == len(a_sum):
        ans = i-1

print(ans)



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

ans = 0
a.sort()
a_sum = [sum(a[:i+1]) for i in range(len(a))]

for i, item in enumerate(a_sum):
    if x < item:
        ans = i
        break
    elif x == item:
        ans = i+1
    elif x > item and i == len(a_sum):
        ans = i

print(ans)



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

ans = 0
a.sort()
a_sum = [sum(a[:i+1]) for i in range(len(a))]

for i, item in enumerate(a_sum):
    if x < item:
        ans = i
        break
    elif x == item:
        ans = i+1
        break
    elif x > item and i == len(a_sum)-1:
        ans = i
        break

print(ans)



Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted
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()
ans = 0
i = 0
while i != n:
    if a[i] > x:
        break
    else:
        x -= a[i]
        ans += 1
        i += 1


print(ans)


n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
i = 0
while x > 0:
    if a[i] > x:
        break
    else:
        x -= a[i]
        ans += 1
        i += 1


print(ans)


n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
i = 0
while i != n:
    if a[i] > x:
        break
    else:
        x -= a[i]
        ans += 1
        i += 1
if x > 0 and i == n:
    ans -= 1
if ans < 0:
    ans = 0
print(ans)


Verdicts: Wrong Answer

Runtime Error

Accepted
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()
wa = 0
cnt = 0
for i in a:
    wa += i
    cnt += 1
    if wa > x:
        print(cnt - 1)
        exit()
        
    elif wa == x:
        print(n)
        exit()
print(n)

n, x= map(int, input().split())
a = list(map(int, input().split()))
a.sort()
wa = 0
cnt = 0
for i in a:
    wa += i
    cnt += 1
    if wa > x:
        print(cnt - 1)
        exit()
        
    elif wa == x:
        print(cnt)
        exit()

n, x= map(int, input().split())
a = list(map(int, input().split()))
a.sort()
wa = 0
cnt = 0
for i in a:
    wa += i
    cnt += 1
    if wa > x:
        print(cnt - 1)
        exit()
        
    elif wa == x:
        print(cnt)
        exit()
print(cnt)

n, x= map(int, input().split())
a = list(map(int, input().split()))
a.sort()
wa = 0
cnt = 0

for i in a:
    wa += i
    cnt += 1
    if wa > x:
        print(cnt - 1)
        exit()
        
    elif wa == x:
        print(cnt)
        exit()
print(cnt - 1)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
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):
#coding:utf-8
n, x = map(int, input().split())
a = list(map(int, input().split()))
child = sorted(a)
ans = 0
candy = 0

for i in range(n):
    candy += child[i]
    if candy == x:
        print(i+1)
        exit()
    elif candy > x:
        print(0)
        exit()

#coding:utf-8
n, x = map(int, input().split())
a = list(map(int, input().split()))
child = sorted(a)

for i in range(n):
    x -= child[i]
    if x < 0:
        break
    elif x == 0:
        print(i+1)
        exit()

print(i)

Verdicts: Wrong Answer

Accepted
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):
def solve(n, x, A):
    A.sort()
    count = 0
    for a in A:
        if a <= x:
            x -= a
            count += 1
        else:
            break
    return count

_n, _x = list(map(int, input().split()))
_A = list(map(int, input().split()))
print(solve(_n, _x, _A))


def solve(n, x, A):
    A.sort()
    count = 0
    for i in range(n):
        if i < n - 1 and A[i] <= x or i == n - 1 and A[i] == x:
            x -= A[i]
            count += 1
        else:
            break
    return count

_n, _x = list(map(int, input().split()))
_A = list(map(int, input().split()))
print(solve(_n, _x, _A))


Verdicts: Wrong Answer

Accepted
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=sorted([int(i)for i in input().split()])
res=0
if sum(a)==x:
    res=n
else:
    for i in range(n):
        if sum(a[:i])<=x:res=len(a[:i])-1
print(max(0,res))

n,x=map(int,input().split())
a=sorted([int(i)for i in input().split()])
res=0
if sum(a)==x:
    res=n
else:
    for i in range(n):
        if sum(a[:i])<=x:res=i
print(res)

Verdicts: Wrong Answer

Accepted
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 = sorted(A)
i = 0
tmp =0
while True:
    if i == len(A):
        print(i)
        exit()
    else:
        tmp += A[i]
        if tmp > x or i == len(A):
            print(i)
            exit()
        else:
            i += 1


N,x = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
i = 0
tmp = 0
while True:
    if i == len(A):
        if  x - tmp == 0:
            print(i)
            exit()
        else:
            print(i - 1)
            exit()
    else:
        tmp += A[i]
        if tmp > x:
            print(i)
            exit()
        else:
            i += 1


Verdicts: Wrong Answer

Accepted
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())
l = list(map(int,input().split()))
l.sort()
for i in range(len(l)):
    sum_l = sum(l[:i+1])
    if sum_l > x:
        print(i)
        break
else:
    print(N)
    

N,x = map(int,input().split())
l = list(map(int,input().split()))
l.sort()
for i in range(len(l)):
    sum_l = sum(l[:i+1])
    if sum_l > x and sum(l[:i])== x:
        print(i)
        break
else:
    print(N)

N,x = map(int,input().split())
l = list(map(int,input().split()))
l.sort()
for i in range(len(l)):
    sum_l = sum(l[:i+1])
    if sum_l > x :
        print(i)
        break
if sum(l) == x:
    print(N)
elif sum(l) < x:
    print(N-1)


Verdicts: Wrong Answer

Wrong Answer

Accepted
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):
y = x
cnt = 0
for ai in a:
    if y - ai >= 0:
        y -= ai
        cnt += 1
if y and cnt == n:
    print(cnt - 1)
else:
    print(cnt)

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

y = x
cnt = 0
for ai in a:
    if y - ai >= 0:
        y -= ai
        cnt += 1
if y and cnt == n:
    print(cnt - 1)
else:
    print(cnt)


Verdicts: Runtime Error

Accepted
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 = list(map(int,input().split()))
A = list(sorted(list(map(int,input().split()))))
for i in range(N,0,-1):
    if sum(A[:i]) <= x:
        print(i)
        break
else:
  print(0)

N,x = list(map(int,input().split()))
A = list(sorted(list(map(int,input().split()))))
for i in range(N,0,-1):
    if sum(A[:i]) == x:
        print(i)
        break
    elif sum(A[:i]) < x and i == N:
        print(i-1)
        break
    elif sum(A[:i]) < x and i != N:
        print(i)
        break
else:
  print(0)

Verdicts: Wrong Answer

Accepted
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_s = map(int, input().split())
sorted_a_s = sorted(a_s)
rest_snaks = x
satisfied_num = 0
for n in range(N):
    if sorted_a_s[n] <= rest_snaks:
        satisfied_num += 1
        rest_snaks -= sorted_a_s[n]
    else:
        rest_snaks = 0

print(satisfied_num)

N, x = map(int, input().split())
a_s = map(int, input().split())
sorted_a_s = sorted(a_s)
rest_snaks = x
satisfied_num = 0
for n in range(N):
    if sorted_a_s[n] <= rest_snaks:
        satisfied_num += 1
        rest_snaks -= sorted_a_s[n]
    else:
        rest_snaks = 0

print(satisfied_num)

N, x = map(int, input().split())
a_s = map(int, input().split())
sorted_a_s = sorted(a_s)
rest_snaks = x
satisfied_num = 0
for n in range(N):
    if sorted_a_s[n] <= rest_snaks:
        if n == (N-1):
            rest_snaks -= sorted_a_s[n]
            if rest_snaks == 0:
                satisfied_num += 1
        else:
            satisfied_num += 1
        rest_snaks -= sorted_a_s[n]
    else:
        rest_snaks = 0

print(satisfied_num)

Verdicts: Wrong Answer

Wrong Answer

Accepted
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):
A,B=list(map(int,input().split()))
C=list(map(int,input().split()))
C.sort()
ans = 0
for i in C:
    if B >= i:
        ans+=1
        B-=i
    else:
        print(ans)
        exit()
print(ans)

A,B=list(map(int,input().split()))
C=list(map(int,input().split()))
C.sort()
ans = 0
for i in C:
    if B >= i:
        ans+=1
        B-=i
    else:
        print(ans)
        exit()
if B > 0:
    ans-=1
print(ans)

Verdicts: Wrong Answer

Accepted
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())
c=list(map(int, input().split()))
c.sort()
ans=0
for g in c:
  if g<=x:
    x-=g
    ans+=1
  else:
    break
if x>0:
  print(0)
else:
  print(ans)

n, x=map(int, input().split())
c=list(map(int, input().split()))
c.sort()
ans=0
for i in range(n-1):
  if c[i]<=x:
    x-=c[i]
    ans+=1
  else:
    break
if c[n-1]==x:
  ans+=1

print(ans)

Verdicts: Wrong Answer

Accepted
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, k = map(int, input().split())
a = list(map(int, input().split()))

ans = 0
is_broken = False
for num in sorted(a):
    if num > k:
        break
        is_broken = True
    else:
        k -= num
        ans += 1
if k != 0 and ans >= 1 and is_broken:
    ans -= 1
print(ans)


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

ans = 0

for num in sorted(a):
    if num > k:
        break
    else:
        k -= num
        ans += 1
print(ans)


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

ans = 0
is_broken = False
for num in sorted(a):
    if num > k:
        is_broken = True
        break
    else:
        k -= num
        ans += 1
if k != 0 and ans >= 1 and not is_broken:
    ans -= 1
print(ans)


Verdicts: Wrong Answer

Wrong Answer

Accepted
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()
for i in range(n):
    x = x - a[i]
    if x >= 0:
        continue
    else:
        print(i)
        break
if x >= 0:
    print(i+1)

n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if x < a[0]:
    print(0)
else:
    for i in range(n):
        x = x - a[i]
        if x > 0:
            continue
        elif x == 0:
            print(i+1)
            break
        else:
            print(i-2)
            break
if x > 0 and x > a[0]:
    print(n-1)

n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
y = x
if y < a[0]:
    print(0)
else:
    for i in range(n):
        x = x - a[i]
        if x > 0:
            continue
        elif x == 0:
            print(i+1)
            break
        elif x < 0:
            print(i)
            break
if x > 0 and y > a[0]:
    print(n-1)

Verdicts: Wrong Answer

Wrong Answer

Accepted
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):
# -*- coding: utf-8 -*-
N, x = map(int, input().split())
an = list(map(int, input().split()))

an.sort()

# print(an)
ans = 0

for ai in an:
    if x >= ai:
        x -= ai
        ans += 1
    else:
        break


if x > 0:
    if ans > 0:
        if ans == len(an):
            pass
        else:
            ans -=1
    else:
        ans = 0

print(ans)


# -*- coding: utf-8 -*-
N, x = map(int, input().split())
an = list(map(int, input().split()))

an.sort()

# print(an)
ans = 0

for ai in an:
    if x >= ai:
        x -= ai
        ans += 1
    else:
        break


if x > 0:
    if ans > 0:
        if ans == len(an):
            ans -=1
        else:
            pass
    else:
        ans = 0

print(ans)


Verdicts: Wrong Answer

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

nums = sorted(list(map(int, input().split())))

count = 0
for i, num in enumerate(nums):
    if num <= x:
        if i != nums.index(num):
            count += 1
            x -= num
        else:
            if num == x:
                count += 1
                x -= num
    else:
        break

print(count)

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

nums = sorted(list(map(int, input().split())))

count = 0
for i, num in enumerate(nums):
    if (i < n-1 and num <= x) or (i == n-1 and num == x):
        count += 1
        x -= num        
    else:
        break

print(count)

Verdicts: Wrong Answer

Accepted
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 = [int(x) for x in input().split()]
a = sorted([int(x) for x in input().split()])

ans = 0

if sum(a) == x:
    ans = N
else:
    for i in range(N):
        if x > a[i]:
            x -= a[i]
            ans += 1

print(ans)

N, x = [int(x) for x in input().split()]
a = sorted([int(x) for x in input().split()])

ans = 0

if sum(a) == x:
    ans = N
else:
    for i in range(N):
        if x >= a[i]:
            x -= a[i]
            ans += 1

print(ans)

N, x = [int(x) for x in input().split()]
a = sorted([int(x) for x in input().split()])

ans = 0

if sum(a) < x:
  	ans = N - 1
elif sum(a) == x:
    ans = N
else:
    for i in range(N):
        if x >= a[i]:
            x -= a[i]
            ans += 1

print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
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()))
if sum(a) == x:
  print(N)
else:
  while sum(a) > x:
    a.remove(max(a))
  print(len(l))


N, x = map(int, input().split())
a = list(map(int, input().split()))
if sum(a) == x:
  print(N)
else:
  sort(a)
  while sum(a) > x:
    a.remove(max(a))
  print(len(l))


N, x = map(int, input().split())
a = list(map(int, input().split()))
if sum(a) == x:
  print(N)
else:
  while sum(a) > x:
    a.remove(max(a))
  l = len(a)
  if l == N:
    print(l - 1)
  else:
    print(l)

Verdicts: Runtime Error

Runtime Error

Accepted
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 = sorted(map(int, input().split()))

sum = 0
i = 0

while (sum <= x) and (i < N)  :
    sum += a[i]
    i += 1

print(i)


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

i = 0
while (i<N) and (x>0):
    x -= a[i]
    i += 1

print(i)


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

i = 0
while (i<N) and (x>=0):
    x -= a[i]
    i += 1

print(i)


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

i = 0

while (i<N) and (x>=0):
    x -= a[i]
    if x>=0:
    i += 1

print(i)


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

i = 0

while (i<N) and (x>=0):
    x -= a[i]
    if x>=0:
        i += 1

print(i)


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

i = 0
while (i<N) and (x>=0):
    if x == 0:
        break
    x -= a[i]
    i += 1

print(i)


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

i = 0

while (i<N) and (x>=0):
    x -= a[i]
    if x>=0:
        i += 1

if (i == N) and (x>0) :
    print(N-1)
else:
    print(i)


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Accepted
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):
hito, ame = map(int, input().split())
NeedAme = list(map(int, input().split()))
NeedAme.sort()

ans = 0
total = 0
for n in NeedAme:
    if total + n <= ame:
        ans += 1
        total += n
    else:
        break

print(ans)


hito, ame = map(int, input().split())
NeedAme = list(map(int, input().split()))
NeedAme.sort()

ans = 0
total = 0
for i in range(0, hito):
    if ((i != hito - 1) and (total + NeedAme[i] <= ame)) or ((i == hito - 1) and (total + NeedAme[i] == ame )):
        ans += 1
        total += NeedAme[i]
    else:
        break

print(ans)


Verdicts: Wrong Answer

Accepted
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):
A,B = map(int,input().split())
X =list(map(int,input().split()))
X = sorted(X)
count = 0
if B == sum(X):
  print(len(X))
elif B <= min(X):
  print(0)
else:
  for i in range(A):
    a = X.pop(0)
    B=B - a
    if B >= 0:
      count += 1
  print(count)

A,B = map(int,input().split())
X =list(map(int,input().split()))
X = sorted(X)
count = 0
for i in range(A):
  a = X.pop(0)
  B=B - a
  if B > 0:
    count += 1
print(count)

A,B = map(int,input().split())
X =list(map(int,input().split()))
X = sorted(X)
count = 0
if B == sum(X):
  print(len(X))
elif B >= min(x):
  print(0)
else:
  for i in range(A):
    a = X.pop(0)
    B=B - a
    if B >= 0:
      count += 1
  print(count)

A,B = map(int,input().split())
X =list(map(int,input().split()))
X = sorted(X)
count = 0
j=len(X)
if B == sum(X):
  print(len(X))
else:
  for i in range(A):
    a = X.pop(0)
    B=B - a
    if B >= 0:
      count += 1
    if B >= 0 and count == j:
      count = count -1
  print(count)

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

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

al = list(map(int,input().split()))

al.sort()

cnt = 0

for a in al[:N]:
  if x >= a:
    x -= a
    cnt += 1
  else:
    break
if al[-1] == x:
  cnt += 1

print(cnt)

  


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

al.sort()

cnt = 0
for a in al:
  x -= a
  cnt += 1
  if x < 0:
    break
print(cnt)
  

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

al = list(map(int,input().split()))

al.sort()

cnt = 0

for a in al:

  x -= a

  if x < 0:

    break

  cnt += 1

print(cnt)

  

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

al = list(map(int,input().split()))

al.sort()

cnt = 0

for a in al[:N-1]:
  if x >= a:
    x -= a
    cnt += 1
  else:
    break
if al[-1] == x:
  cnt += 1

print(cnt)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
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):
m,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
cnt=0
res=0
for i in a:
    cnt+=i
    if cnt > x:
        break
    res+=1
if a[0] > x:
    res=0
print(res)

m,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
cnt=0
res=0
for i in range(0,m):
    cnt += a[i]
    if cnt > x:
        res=i
        break
    elif cnt==x:
        res=i+1
        break
    if i == m-1 and cnt<x:
        res=m-1
if a[0] > x:
    res=0
print(res)

Verdicts: Wrong Answer

Accepted
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):
a = input().split()
a = [int(i) for i in a]
b = input().split()
b = [int(i) for i in b]
b = sorted(b)
output = 0
end = False

for i in range(len(b)-  1):
	if a[1] - b[i] > 0:
		a[1] += -b[i]
		output += 1
	elif(a[1] - b[i] == 0):
		output += 1
		end = True
		break
	else:
		end = True
		pass
		
if end == False:
	if a[1] - b[-1] < 0:
		output -= 1
	elif a[1] - b[-1] > 0:
		output -= 1
	else:
		output += 1
		 
print(output)

a = input().split()
a = [int(i) for i in a]
b = input().split()
b = [int(i) for i in b]
b = sorted(b)
output = 0
end = False

for i in range(len(b)-  1):
	if a[1] - b[i] > 0:
		a[1] += -b[i]
		output += 1
	elif(a[1] - b[i] == 0):
		output += 1
		end = True
		break
	else:
		end = True
		break
		
if end == False:
	if a[1] - b[-1] == 0:
		output += 1
		 
print(output)

Verdicts: Wrong Answer

Accepted
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().strip().split())
a  = list(map(int , input().strip().split()))
a.sort()
count = 0

for i in a:
  if x - i < 0:
    break
  x -= i
  count += 1

print(count)

n , x = map(int , input().strip().split())
a  = list(map(int , input().strip().split()))
a.sort()
if sum(a) < x:
  count = -1
else:
  count = 0

for i in a:
  if x - i < 0:
    break
  x -= i
  count += 1

print(count)

Verdicts: Wrong Answer

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

ans = 1-1
for i in a:
  x -= i
  if x < 0:
    break
  ans += 1
print(ans)


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

ans = 0
for i in a:
  x -= i
  if x < 0:
    break
  ans += 1
print(ans)


n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
a.reverse()
ans = 0

for i in a:
  x -= i
  if x<0:
    break
  ans += 1
print(ans)


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

ans = 0
for i in a:
  x -= i
  if x < 0:
    break
  ans += 1
print(ans)


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

ans = 0
for i in a:
  x -= i
  if x < 0:
    break
  ans += 1
print(ans)


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

ans = 0
for i in a:
  x -= i
  if x <= 0:
    break
  ans += 1
print(ans)


n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
 
for i in a:
  x -= i
  if x < 0:
    break
  ans += 1
if x > 0:
  if ans > 0:
    ans -= 1
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
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 = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]

count = 0
for a in sorted(A):
    if X >= a:
        count += 1
        X -= a

print(count)


N, X = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]

count = 0
for i, a in enumerate(sorted(A)):
    if X >= a:
        count += 1
        X -= a

if count == N and X > 0:
    count -= 1

print(count)


Verdicts: Wrong Answer

Accepted