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

n,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans = 0
if sum(a) == x:
    ans = n
elif sum(a) < x:
    ans = n - 1
else:
    for i in range(n):
        if a[i] <= x:
            ans += 1
            x -= a[i]
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()
ans=0
for i in range(N)
  x = x-a[i]
  if x>=0:
    ans+=1
  else:
    break
print(ans)

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

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

Verdicts: Runtime Error

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())))
cnt=0
for i in A:
  if x >= i:
    x -= i
    cnt+=1
  else:
    break
print(cnt)


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

ans = 0
for i in range(N):
  if x >= A[i]:
    ans += 1
    x -= A[i]
  else:
    print(ans)
    break
else:
  print(ans)

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

A.sort()

print(A)
ans = 0
for i in range(N):
  if x > A[i]:
    ans += 1
    x -= A[i]
  elif x == A[i]:
    print(ans+1)
    break
  else:
    print(ans -1)
    break
else:
  print(ans-1)


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

A.sort()

ans = 0
for i in range(N):
  if x > A[i]:
    ans += 1
    x -= A[i]
  elif x == A[i]:
    print(ans+1)
    break
  elif i+1 == N:
    print(ans -1)
    break
  else:
    print(ans)
    break


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

A.sort()
ans = 0

for i in range(N):
  if x > A[i]:
    if i+1 == N:
      print(N-1)
      exit()
    else:
      ans += 1
      x -= A[i]
  elif x == A[i]:
    ans += 1
    print(ans)
    exit()
  else:
    print(ans)
    exit()

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):
N,x = map(int,input().split())
a_list = list(map(int,input().split()))
a_list_sort = sorted(a_list)
#print(a_list)
#print(a_list_sort)
count = 0

if sum(a_list) <= x :
	count = N
else:
	for i in range(N):
		if sum(a_list_sort[:i+1]) <= x:
			continue	
		else:
			count = i
			break
print(count)

N,x = map(int,input().split())
a_list = list(map(int,input().split()))
a_list_sort = sorted(a_list)
#print(a_list)
#print(a_list_sort)
count = 0

if sum(a_list) < x :
	count = N-1
elif sum(a_list) == x :
	count = N
else:
	for i in range(N):
		if sum(a_list_sort[:i+1]) <= x:
			continue	
		else:
			count = i
			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 = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans = 0
judge = [False for i in range(N)]
# print(judge)
for i in range(N):
    if x-a[i]>=0:
        judge[i]=True
        x-=a[i]
temp_count=0
for i in range(N):
    if judge[i]:
        temp_count+=1
# print(judge)
if sum(a)<x:
    print(temp_count-1)
else:
    print(temp_count)


N,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans = 0
judge = [False for i in range(N)]
True_X=x
# print(judge)
for i in range(N):
    if x-a[i]>=0:
        judge[i]=True
        x-=a[i]
temp_count=0
for i in range(N):
    if judge[i]:
        temp_count+=1
# print(judge)
if sum(a)<True_X:
    print(temp_count-1)
else:
    print(temp_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):
#-*-coding:utf-8-*-

def main():
    n, x = map(int, input().split())
    a_list = list(map(int, input().split()))
    a_list.sort()
    total = 0
    ans = 0
    for i in range(n):
        total += a_list[i]
        if total <= x:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

#-*-coding:utf-8-*-

def main():
    n, x = map(int, input().split())
    a_list = list(map(int, input().split()))
    a_list.sort()
    total = 0
    ans = 0
    for i in range(n):
        total += a_list[i]
        if total <= x:
            ans += 1
    if total < x:
        print(ans - 1)
    else:
        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 = list(map(int, input().split()))
a.sort()
b = 0
for k in range(N):
  b += a[k]
  if b > x:
    print(k)
    break

import numpy as np
N, x = map(int, input().split())
a = np.array(list(map(int, input().split())))
a.sort()
s = np.cumsum(a)
b = (s <= x)
if b.all():
  if s[-1] == x:
    c = b.sum()
  else:
    c = b.sum() - 1
elif b.any():
  c = b.sum()
  r = x - s[c-1]
  if (r == a[c:]).any():
    c += 1
else:
  c = 0
print(c)

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

N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
sum_ = 0 
ans = 0 
for i in range(N):
        sum_ += a[i]
        if sum_ > x:
                break
        ans += 1
print(ans)

N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0 
for i in range(N):
        x -= a[i]
        if x < 0:
                break
        ans += 1
if x > 0:
        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())
src = list(map(int,input().split()))
src.sort()

x = 0
ans = 0
for a in src:
    if x+a > X: break
    ans += 1
    x += a
print(ans)

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

ans = 0
for a in A:
    if X-a < 0: break
    X -= a
    ans += 1
else:
    if 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,x = map(int,input().split())
alist = list(map(int,input().split()))
alist.sort()
counter = 0
for a in alist:
    x -= a
    if x>=0:
        counter += 1
    else:
        break
print(counter)


N,x = map(int,input().split())
alist = list(map(int,input().split()))
alist.sort()
counter = 0
for i in range(N):
    x -= alist[i]
    if x>=0:
        if i!=N-1:
            counter += 1
        else:
            if x==0:
                counter += 1
    else:
        break
print(counter)


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,m=map(int,input().split())
hoge=list(map(int,input().split()))
hoge.sort()
ans=0
for i in range(n):
  if(hoge[i]<=m):
    ans+=1
    m-=hoge[i]
  else:
    break
if(m==0):
  print(ans)
else:
  if(sum(hoge)<m):
    print(n-1)
  else:
    print(ans)

n,m=map(int,input().split())
hoge=list(map(int,input().split()))
hoge.sort()

if(sum(hoge)<m):
  print(n-1)
  exit()

ans=0
for i in range(n):
  if(hoge[i]<=m):
    ans+=1
    m-=hoge[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):
# AGC 027 A - Candy Distribution Again
N, x = map(int,input().split())
an = list(map(int,input().split()))

ak =[] 
while len(an) > 0:
    ak.append(min(an))
    del an[an.index(min(an))]

count = 0
for i in range(N):
    if x > 0:
        x -= ak[i]
        if i != N-1:
            count += 1
            print('a'+ str(x))
        if i == N-1:
            if x == 0:
                count += 1
            else:
                break
    if x < 0:
        count -= 1
        print('b'+ str(x))
        break

    if x == 0:
        print('c'+ str(x))
        break
print(count)

# AGC 027 A - Candy Distribution Again
N, x = map(int,input().split())
an = list(map(int,input().split()))

ak =[] 
while len(an) > 0:
    ak.append(min(an))
    del an[an.index(min(an))]

count = 0
for i in range(N):
    if x > 0:
        x -= ak[i]
        if i != N-1:
            count += 1
        if i == N-1:
            if x == 0:
                count += 1
            else:
                break
    if x < 0:
        count -= 1
        break

    if x == 0:
        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 = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
children = [0] * N
a.sort()
kashi = 0
while kashi < x:
    for i in range(0,N):
        kashi += a[i]
        children[i] += 1
        if kashi > x:
            kashi -= a[i]
            children[i] -= 1
            break
    if kashi == 0:
        break
print(N - children.count(0))

N, x = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
children = [0] * N
a.sort()
kashi = 0
n = N
if a[0] > x:
    print(0)
elif sum(a) == x:
    print(N)
else:
    while kashi < x:
        for i in range(0,n):
            kashi += a[i]
            children[i] += 1
            if kashi > x:
                kashi -= a[i]
                children[i] -= 1
                break
#        print(kashi)
        n -= 1
        if n < 1:
            break
#    print(children)
    print(N - children.count(0))

N, x = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
children = [0] * N
a.sort()
kashi = 0
n = N
if a[0] > x:
    print(0)
elif sum(a) == x:
    print(N)
else:
    for i in range(0,n):
        if kashi > x:
            break        
        kashi += a[i]
        children[i] += 1
#     print(kashi)
    if kashi == x :
        print(N - children.count(0))
    else:
        print(N - children.count(0) - 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):
N, x = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

A.sort()

ans = 0
for a in A:
    if a <= x:
        ans += 1
        x -= a
    else:
        break

print(ans)

N, x = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
B = [0 for _ in range(N)]

A.sort()

ans = 0
for i in range(len(A)):
    if i == N - 1:
        B[i] = x
        break
    if x - A[i] >= 0:
        B[i] = A[i]
        x -= A[i]
    else:
        B[i] = 0
for i in range(len(A)):
    if A[i] == B[i]:
        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):
a,b=map(int,input().split())
c=list(map(int,input().split()))
c.sort()
i=0
total=0
while True:
    if b>=c[i]:
        b=b-c[i]
        total+=1
    else:
        print(total)
        break

a,b=map(int,input().split())
c=list(map(int,input().split()))
c.sort()
i=0
total=0
while True:
    if b<c[i]:
        print(total)
        break
    elif i==a-1:
        if b==c[i]:
            print(total+1)
        else:
            print(total)
        break
    else:
        total+=1
        b=b-c[i]
        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 = [int(i) for i in input().split(" ")]
lst = [int(i) for i in input().split(" ")]

lst.sort(reverse = True)
cnt = 0

for i in range(0,N):
  if x >= lst[i]:
    x -= lst[i]
    cnt += 1
  else:
    break
    
print(cnt)


N, x = [int(i) for i in input().split(" ")]
lst = [int(i) for i in input().split(" ")]
 
lst.sort()
cnt = 0
 
for i in range(0,N):
  if x >= lst[i]:
    x -= lst[i]
    cnt += 1
  else:
    break
    
print(cnt)

N, x = [int(i) for i in input().split(" ")]
lst = [int(i) for i in input().split(" ")]

lst.sort(reverse = True)
cnt = 0

for i in range(0,N):
  if x >= lst[i]:
    cnt += 1
  else:
    break
    
print(cnt)


N, x = [int(i) for i in input().split(" ")]
lst = [int(i) for i in input().split(" ")]

lst.sort(reverse = True)
cnt = 0

while x > lst[cnt]:
  x -= lst[cnt]
  cnt += 1
  
print(cnt)

N, x = [int(i) for i in input().split(" ")]
lst = [int(i) for i in input().split(" ")]

lst.sort(reverse = True)
cnt = 0

for i in range(0,N):
  x -= lst[i]
  if x >= 0:
    cnt += 1
  else:
    break
    
print(cnt)

N, x = [int(i) for i in input().split(" ")]
lst = [int(i) for i in input().split(" ")]
 
lst.sort()
cnt = 0
 
for i in range(0,N-1):
  if x >= lst[i]:
    x -= lst[i]
    cnt += 1
  else:
    break

    
print(cnt+(x==lst[N-1]))


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

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 = input().split()
for i in range(N):
  a_s[i] = int(a_s[i])
  
a_s = sorted(a_s)

ans = 0
sum_ = 0
for i in range(N):
  if sum_ + a_s[i] <= x:
    sum_ += a_s[i]
    ans += 1
  else:
    break
print(ans)

N, x = map(int, input().split())
a_s = input().split()
for i in range(N):
  a_s[i] = int(a_s[i])
  
a_s = sorted(a_s)

ans = 0
sum_ = 0
for i in range(N):
  if (sum_ + a_s[i] <= x)&(i<N-1):
    sum_ += a_s[i]
    ans += 1
  elif (sum_ + a_s[i] == x)&(i==N-1):
    ans += 1
  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):


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

A.sort(reverse=True)
candy = 0
ans = 0
for i in A:
    candy += i
    if candy <= x:
        ans += 1
print(ans)



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

A.sort()
candy = 0
ans = 0
for i in A:
    candy += i
    if candy <= x:
        ans += 1
print(ans)



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

A.sort()
candy = 0
ans = 0
for i in A:
    candy += i
    if candy <= x:
        ans += 1
if candy < x:
    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()
ans = 0
for i in a:
  if x >= i:
    x -= i
    ans += 1
print(ans)

N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in a:
  if x >= i:
    x -= i
    ans += 1
if x == 0:
  print(ans)
else:
  print(min(N - 1, 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()) )

happy=0
a.sort()

for i in range(N):
    
    if a[i] > x:
        break

    else:
        x=x-a[i]
        happy=happy+1

print(happy)


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

happy=0
a.sort()

for i in range(N):
    
    if a[i] > x:
        break

    else:
        x=x-a[i]
        happy=happy+1

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


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())))
for i in range(n):
    if x<A[i]:
        print(i)
        break
    x-=A[i]
else:print(n)

    

n,x=map(int,input().split())
A=sorted(list(map(int,input().split())))
num=0
for i in range(n):
    if x<A[i]:
        print(i)
        break
else:print(n)

    

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


    

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


    

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):
N,n=map(int,input().split())
A=list(map(int,input().split()))
A.sort()

ans=0
i=0
while A[i]<=n:
  ans+=1
  i+=1
  if i==N:
    break
print(ans)

N,n=map(int,input().split())
A=list(map(int,input().split()))
A.sort()

ans=0
i=0
while A[i]<=n:
  if i==N-1:
    if n==A[i]:
      ans+=1
    break
  else:
    ans+=1
    n-=A[i]
    i+=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):
import numpy as np

n,X = map(int,input().split())
xs = np.array(list(map(int,input().split())))
cumsumx =np.insert(np.cumsum(xs),0,0)

print(0)

import numpy as np

n,X = map(int,input().split())
xs = np.array(list(map(int,input().split())))
cumsumx =np.insert(np.cumsum(xs),0,0)

def energy(k):
    nok = n//k
    acm = (n+k)*X
    for i in range(1,nok+1):
        relsum = cumsumx[-(i-1)*k-1] - cumsumx[-i*k-1]
        if i == 1:
            acm += 5*relsum
        else:
            acm += (2*i+1)*relsum
    relsum = cumsumx[-nok*k-1]
    acm += (2*(nok+1)+1)*relsum
    return(acm)

ans = -1
for j in range (1,n):
    tmp = energy(j)
    if tmp < ans or ans == -1:
        ans =tmp

print(ans)







n,m = map(int,input().split())
s = list(input())
edges = [tuple(map(int,input().split())) for i in range(m)]


def addEdge(graph,u,v):
    graph[u].add(v)


def deleteNode(graph,node):
    graph.pop(node,None)

from collections import defaultdict
graphAB = defaultdict(set)
graphABopp = defaultdict(set)

connodes = set()
for i,j in edges:
    ii = min(i,j)
    jj = max(i,j)
    addEdge(graphAB,ii,jj)
    addEdge(graphABopp,jj,ii)
    if i != j:
        connodes.add(i)
        connodes.add(j)



def adjAB(node):
    Aflag = 'A' in map(lambda x:s[x-1],graphAB[node])
    Aflag = Aflag or 'A' in map(lambda x:s[x-1],graphABopp[node])
    Bflag = 'B' in map(lambda x:s[x-1],graphAB[node])
    Bflag = Bflag or 'B' in map(lambda x:s[x-1],graphABopp[node])
    if Aflag and Bflag:
        return(True)
    else:
        return(False)



visitlist = [i for i in connodes if not adjAB(i)]
#print(visitset)

while bool(visitlist):
    i = visitlist.pop()
    for j in graphAB[i]:
        graphABopp[j].remove(i)
        if not adjAB(j):
            visitlist.append(j)
            #print(visitset,'add')
    for j in graphABopp[i]:
        graphAB[j].remove(i)
        if not adjAB(j):
            visitlist.append(j)
            #print(visitset,'add')
    graphAB.pop(i,None)
    graphABopp.pop(i,None)


#print(graphABopp)


if graphAB == {} and graphABopp == {}:
    print('No')
else:
    print('Yes')





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

ans = 0
acm = 0
for i in ass:
    acm += i
    if x >= acm:
        ans +=1

if acm < x:
    ans -= 1

print(ans)


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=input().split()
X=int(x)
n=int(N)
y=0
A = [int(i) for i in input().split()]
A.sort()
for z in range(n):
  y+=A[z]
  if y>=X:
    print(z+1)
    break

N,x=input().split()
X=int(x)
n=int(N)
y=0
A = [int(i) for i in input().split()]
A.sort()
for z in range(n):
  y+=A[z]
  if y>=X:
    print(z+1)
    break
else:
  print(N)

N,x=input().split()
X=int(x)
n=int(N)
y=0
A = [int(i) for i in input().split()]
A.sort()
for z in range(n):
  y+=A[z]
  if y>=X:
    print(z+1)
    break
else:
  print(N)

N,x=input().split()
X=int(x)
n=int(N)
y=0
A = [int(i) for i in input().split()]
A.sort()
for z in range(n):
  if y>=X:
    break
    print(z+1)
  y+=A[z]
if y>=X:
  print(N)
else:
  print(N)

N,x=input().split()
X=int(x)
n=int(N)
y=0
A = [int(i) for i in input().split()]
A.sort()
for z in range(n):
  y+=A[z]
  if y>=X:
    if y==X:
      print(z+1)
    else:
      print(z)
    break
else:
  print(n-1)

Verdicts: 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):
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.buffer.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

def heapsort(iterable):
    h = []
    for value in iterable:
        heapq.heappush(h, value)
    return [heapq.heappop(h) for i in range(len(h))]

n, k = rm()
a = rl()
a = heapsort(a)
cnt = 0
for i in a:
    k -= i
    if k < 0:
        break
    else:
        cnt += 1
print(cnt)




import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.buffer.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

def heapsort(iterable):
    h = []
    for value in iterable:
        heapq.heappush(h, value)
    return [heapq.heappop(h) for i in range(len(h))]

n, k = rm()
a = rl()
a = heapsort(a)
cnt = 0
for i in a:
    k -= i
    if k < 0:
        break
    else:
        cnt += 1
else:
    if k != 0:
        cnt -= 1
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 = sorted(a)

ans = 0
temp = x

while ans < n:
    temp -= a[ans]
    ans += 1
    if temp == 0:
        break
    elif temp < 0:
        ans -= 1
        break

print(ans)


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

a = sorted(a)

ans = 0
temp = x

while ans < n:
    temp -= a[ans]
    ans += 1
    if temp == 0:
        break
    elif temp < 0:
        ans -= 1
        break

if ans == n and temp > 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())
a_list = sorted(list(map(int, input().split())))
sum = 0
num = 0

while sum < x and num <= N:
    sum += a_list[num]
    num += 1
    
print(num)

N, x = map(int, input().split())
a_list = sorted(list(map(int, input().split())))
sum = 0
num = 0

while sum < x and num + 1 <= N:
    sum += a_list[num]
    num += 1
    
print(num)

N, x = map(int, input().split())
a_list = sorted(list(map(int, input().split())))
sum = 0
num = 0

while sum < x:
    sum += a_list[num]
    num += 1
    
print(num)

N, x = map(int, input().split())
a_list = sorted(list(map(int, input().split())))
sum = 0
num = 0

while sum < x:
    sum += a_list[num]
    num += 1
    print(sum)
    
print(num)

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

for i in range(N):
    x = x - a_list[i]
    if x < 0:
        break
if i == N-1 and x == 0:
    i += 1

print(i)



Verdicts: Runtime Error

Wrong Answer

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

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


n,x = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a)
res = 0
p = 0
for i in a:
    x -= i
    if x < 0:
        x += i
        break
    res += 1
    p += 1
else:
    if x > 0:
        res -= 1
#print(p, a[p:])
print(res + (x in a[p:]))


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.sort()
ans = 0

for i in arr:
    x -= i
    if x < 0:
        break
    else:
        ans += 1
    if x > 0 and ans > 0:
        ans -= 1

print(ans)

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

arr.sort()
ans = 0
for consume_v in arr:
    if x >= consume_v:
        x -= consume_v
        ans += 1
    elif x > 0 and ans > 0:
        ans -= 1
    else:
        break
print(ans)

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

arr.sort()
ans = 0

for i in arr:
    print(ans)
    x -= i
    if x < 0:
        break
    else:
        ans += 1
if x > 0 and ans > 0:
    ans -= 1

print(ans)

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

arr.sort()
ans = 0
for consume_v in arr:
    if x >= consume_v:
        x -= consume_v
        ans += 1
    elif x > 0 and ans > 0:
        ans -= 1
        break
    else:
        break
print(ans)

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

arr.sort()
ans = 0

for i in arr:
    x -= i
    if x < 0:
        break
    else:
        ans += 1
if x > 0 and ans > 0:
    ans -= 1

print(ans)

Verdicts: 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):

import bisect


n, x = map(int, input().split())
a = list(sorted(map(int, input().split())))
if x == sum(x):
    print(n)
else:
    acc = [0 for i in range(n)]
    acc[0] = a[0]
    for i in range(1, n):
        acc[i] += a[i - 1] + a[i]
    index = bisect.bisect_right(acc, x)
    if index == n:
        print(index - 1)




import bisect


n, x = map(int, input().split())
a = list(sorted(map(int, input().split())))
acc = [0 for i in range(n)]
acc[0] = a[0]
for i in range(1, n):
    acc[i] += a[i - 1] + a[i]
index = bisect.bisect_right(acc, x)
print(index)


import bisect


n, x = map(int, input().split())
a = list(sorted(map(int, input().split())))
acc = [0 for i in range(n)]
acc[0] = a[0]
for i in range(1, n):
    acc[i] += a[i - 1] + a[i]
index = bisect.bisect_left(acc, x)
print(index)

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


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
for ai in a:
    if x >= ai:
        x -= ai
        ans += 1
    else:
        break

print(ans)

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

a.sort()

ans = 0
for ai in a:
    if x >= ai:
        x -= ai
        ans += 1
    else:
        break
else:
  if 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, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a_sort =sorted(a)
cou = 0
for i in range(N):
    if x >= a_sort[i]:
        x -= a_sort[i]
        cou += 1
print(cou)

a_sort =sorted(a)
cou = 0
for i in range(N):
    if x >= a_sort[i]:
        cou += 1
        x -= a_sort[i]
print(cou)

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

ans = 0
for i in a:
    x -= i
    if x >= 0:
        ans += 1

print(ans)

N, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a_sort =sorted(a)
cou = 0
for i in range(N):
    if x >= a_sort[i]:
        cou += 1
print(cou)

N, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a_sort =sorted(a)
cou = 0
for i in range(N):
    if x >= a_sort[i]:
        x -= a_sort[i]
        cou += 1
print(cou)

N, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a_sort =sorted(a)
cou = 0
for i in range(N):
    if x >= a_sort[i]:
        x -= a_sort[i]
        cou += 1
if x > 0 and cou == N:
    print(cou-1)
else:
    print(cou)

Verdicts: Wrong Answer

Runtime Error

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

N,x = map(int, input().split())
A = sorted(map(int, input().split()))
s = 0
for i in range(N):
  x -= A[i]
  if x<0:
    break
  else:
    s += 1
print(s if x<=0 else s-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):
from itertools import accumulate
from bisect import bisect

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

arr.sort()
sum_arr = list(accumulate(arr))

idx = bisect(arr, x)
print(idx)


from itertools import accumulate
from bisect import bisect

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

arr.sort()
sum_arr = list(accumulate(arr))

idx = bisect(sum_arr, x)

if idx == n and sum_arr[n - 1] != x:
    idx -= 1

print(idx)


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 = 0

for i in range(N):
  x -= A[i]
  if x >= 0:
    ans += 1
  else:
    break
    
if x > 0:
  print(ans-1)
else:
  print(ans)

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

A.sort()

ans = 0

for i in range(n):
  x -= A[i]
  if x >= 0:
    ans += 1
  else:
    break
    
if x > 0:
  print(ans-1)
else:
  print(ans)


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()))
A.sort()
A = [0] + A
for i in range(N):
  A[i+1] = A[i]+A[i+1]
  if A[i+1]>X:
    print(i)
    exit()
print(N)


N , X = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
A = [0] + A
for i in range(N):
  A[i+1] = A[i]+A[i+1]
  if A[i+1]>X:
    break
if i==N-1 and X==A[N]:
  print(N)
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())
a = list(map(int,input().split()))
a = sorted(a)
count = 0
while(x >= 0):
  if(count == N):
    break
  tmp = a.pop(0)
  if(x >= tmp):
    x = x - tmp
    count += 1
  else:
    break
print(str(count))

N,x = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a)
count = 0
while(x >= 0):
  if(count == N):
    break
  tmp = a.pop(0)
  if(x >= tmp):
    x = x - tmp
    count += 1
  else:
    break
if(count == N and x != 0):
  count -= 1
print(str(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()))

if sum(a) ==x:
    print(n)
else:
    a.sort()
    for i in range(n):
        if x >= a[i]:
            ans += 1
            x -= a[i]
        else:
            break




print(ans-1)

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

if sum(a) ==x:
    print(n)
else:
    a.sort()
    for i in range(n):
        if x >= a[i]:
            ans += 1
            x -= a[i]
        else:
            break

    if ans == n:
        ans -= 1


    print(ans)

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()))	
ans=0
A.sort()
for i in A:
    x=x-i
    if x >= 0:
        ans=ans+1
print(ans)

N,x = map(int,input().split())
A = list(map(int,input().split()))	
ans=0
A.sort()
for i in A:
    x=x-i
    if x < 0:
    
    else:
        ans=ans+1
print(ans)

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

Verdicts: Wrong Answer

Runtime Error

Accepted