Problem:
 Score : 200 points    Problem Statement 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.      Constraints  All values in input are integers.  2 \leq N \leq 100  1 \leq x \leq 10^9  1 \leq a_i \leq 10^9         Input Input is given from Standard Input in the following format:  N  x  a_1  a_2  ...  a_N       Output Print the maximum possible number of happy children.        Sample Input 1 3 70
20 30 10      Sample Output 1 2  One optimal way to distribute sweets is (20, 30, 20) .       Sample Input 2 3 10
20 30 10      Sample Output 2 1  The optimal way to distribute sweets is (0, 0, 10) .       Sample Input 3 4 1111
1 10 100 1000      Sample Output 3 4  The optimal way to distribute sweets is (1, 10, 100, 1000) .       Sample Input 4 2 10
20 20      Sample Output 4 0  No children will be happy, no matter how the sweets are distributed.

Solution (Python):
import math
N,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()

conf=0
for i in range(N):
    if i==N-1:
        if a[i]==x:
            conf=conf+1
    else:
        if a[i]<=x:
            conf=conf+1
            x=x-a[i]
        else:
            break
print(conf)

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

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

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

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

A.sort()

required = sum(A)

if required == x:
    ans = N
elif required < x:  
    ans = N - 1
else:  
    sm = 0
    ans = 0
    for ai in A:
        sm += ai
        if sm <= x:
            ans += 1
        else:
            break

print(ans)

Solution (Python):
def main():
    
    
    
    
    
    
    
    
    
    
    
    
    
    n,x=map(int,input().split())
    a=sorted(map(int,input().split()))
    cnt = 0
    suma = sum(a)
    if suma < x:
        print(n-1)
    elif suma == x:
        print(n)
    else:
        for i in a:
            if x < i:
                break
            cnt+=1
            x-= i
        print(cnt)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
N, x = map(int, input().split())
a = sorted(map(int, input().split()))


ans = 0
score_x  = x

if score_x < a[0]:
    print(0)
    sys.exit()
    
for  i in range(N):
    if i == (N-1):
        if a[i] == score_x:
            ans = ans + 1
            score_x = (score_x - a[i])
        else:
            break      
    if score_x  >= a[i]:
        score_x = (score_x - a[i])
        ans = ans + 1


print(ans)

Solution (Python):
from itertools import accumulate
from bisect import bisect
N,x,*A=map(int, open(0).read().split())
B=list(accumulate(sorted(A)))
i=bisect(B, x)
if i==N and sum(A)!=x:
    i=N-1
print(i)

Solution (Python):
n, x = list(map(int, input().split(' ')))

ss = list(map(int, input().split(' ')))
    
r = x
count = 0    
for s in sorted(ss):
    if r - s < 0:
        break
    else:
        n -= 1
        r -= s
        count += 1
if r > 0 and n <= 0:
    count -= 1
print(count)

Solution (Python):
n, x = map(int, input().split())
li_a = list(map(int, input().split()))

answer = 0
id = -1

for idx, a in enumerate(sorted(li_a)):
    if x >= a:
        answer += 1
        x -= a
        id = idx
    else:
        break
if answer == 0:
    print(answer)
elif x == 0:
    print(answer)
else:
    if id == (n -1):
        print(answer - 1)
    else:
        print(answer)

Solution (Python):
n, x = map(int, input().split())
res = 0
dat = list(map(int, input().split()))

dat.sort()

for i in range(n):
    if x >= dat[i]:
        res += 1
        x -= dat[i]
    else:
        break
if x != 0 and res != 0 and res == n:
    res -= 1
print(res)

Solution (Python):
N,x=[int(i) for i in input().split()]
a = [int(x) for x in input().split()]
a.sort()
cnt=0
for k in a:
	x -= k
	if x < 0:
		break
	cnt +=1
if x >0:
	cnt -=1
print(cnt)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
import itertools

def main():
    N,x = map(int,input().split())
    a = sorted(list(map(int,input().split())))
    accum_a = list(itertools.accumulate(a))
    ans = 0
    for i in range(N):
        if accum_a[i] > x:
            break
        else:
            ans += 1
    if accum_a[-1] < x:
        ans -= 1
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):




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

a_list.sort()
x_remain=x

result = -1
for i in range(n):
    x_remain -= a_list[i]
    
    if x_remain == 0:
        result = i+1
        break
    if x_remain < 0:
        result = i
        break

if result == -1 :
    result = n-1

print(result)

Solution (Python):
N, x = map(int,input().split())
a = list(map(int,input().split()))
count = 0
a_new = sorted(a)

for i in range(0, N):
	count += a_new[i]
	if x == count:
		index = i + 1
		break
	if count > x:
		index = i
		break
	index = i

print(str(index))

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    N, x = map(int, input().split())
    a_list = list(map(int, input().split()))
    ans = 0
    for a in sorted(a_list):
        if a <= x:
            ans += 1
            x -= a
        else:
            break
    if x == 0 or ans != N:
        print(ans)
    else:
        print(max(ans - 1, 0))

if __name__ == '__main__':
    main()

Solution (Python):
N, x = map(int, input().split())
list_a = [int(x) for x in input().split()]

list_a.sort()
total = sum(list_a)
if x < list_a[0] :
    print(0)
    exit()
if x > total :
    print(len(list_a)-1)
    exit()
ans = 0

for i in range(N) :
    if list_a[i] <= x :
        x -= list_a[i]
        ans += 1

print(ans)

Solution (Python):
[N, x] = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
count = 0
i = 0
while x > 0 and i <= len(a):
  x -= a[i]
  if i == len(a)-1:
    if x != 0:
      break
  if x >= 0:
    count += 1
  i += 1
  
print(count)

Solution (Python):
from itertools import accumulate
import bisect
N,x = map(int,input().split())
A = sorted(list(map(int,input().split())))
A = list(accumulate(A))
ind = bisect.bisect_right(A,x)-1
if ind == -1:
    print(0)
elif ind == N-1:
    if A[ind] == x:
        print(ind+1)
    else:
        print(ind)
else:
    print(ind+1)

Solution (Python):
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]))

Solution (Python):
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

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

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

a.sort()

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

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

Solution (Python):
n, x = map(int, input().split())
aList = list(map(int, input().split()))
aList.sort()
sums = 0
i = 0
while sums < x and i < n:
    sums += aList[i]
    i += 1
i -= 1
if sums == x:
    i += 1
print(i)

Solution (Python):
n, x = map(int, input().split())
a = sorted([int(i) for i in input().split()])
ans = 0

for i in range(n):
	x -= a[i]
	if x >= 0:
		ans += 1


if x > 0:
	print(ans -1)
else:
	print(ans)

Solution (Python):
N, x = map(int, input().split())
a = list(map(int, input().split()))
s_a = sorted(a)
cnt = 0

for i in range(N-1):
    if(s_a[i] <= x):
        cnt += 1
        x -= s_a[i]
if(s_a[N-1] - x == 0):
    cnt += 1
print(cnt)

Solution (Python):
try:
  N, x = map(int, input().split())
  a = list(map(int, input().split()))
  a_ = sorted(a)
  cnt = 0
  for i in range(len(a_)-1):
      if a_[i]<=x:
          cnt += 1
          x = x-a_[i]
  if a_[len(a_)-1]-x==0:
      cnt += 1
  print(cnt)
except EOFError:
  pass

Solution (Python):
N, x = map(int, input().split())
array = list(map(int, input().split()))
a = sorted(array, reverse=False)

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

Solution (Python):
N, x = [int(z) for z in input().split()]
children = [int(z) for z in input().split()]

children.sort()
sum = 0

for i in children:
    sum += i

if sum < x:
    print(N - 1)


else:
    cnt = 0
    for i in children:
        if x - i < 0:
            break
        else:
            x -= i
            cnt += 1
    print(cnt)

Solution (Python):
N, x = [int(z) for z in input().split()]
children = [int(z) for z in input().split()]

children.sort()
sum = 0

for i in children:
    sum += i

if sum < x:
    print(N - 1)
elif sum == x:
    print(N)
else:
    cnt = 0
    for i in children:
        if x - i < 0:
            break
        else:
            x -= i
            cnt += 1
    print(cnt)

Solution (Python):
N, x = map(int, input().split())
L = list(map(int,input().split()))
L_sorted = sorted(L, reverse=False)

remain = x
ans = 0
for j in range(N):
    if remain>= L_sorted[j] and j != N-1:
        remain = remain - L_sorted[j]
        ans += 1
    
    if j == N-1 and L_sorted[j] == remain:
        ans += 1
print(ans)

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

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

A.sort()
c = 0
for i in A:
    x -= i
    if x >= 0:
        c += 1
    else:
        break

if x > 0:
    c -= 1

print(c)

Solution (Python):
n, x = map(int, input().split())
a = list(map(int, input().split()))
if sum(a) == x:
    print(n)
elif sum(a) < x:
    print(n-1)
else:
    a = sorted(a)
    total = 0
    for i in range(n):
        total += a[i]
        if total == x:
            print(i+1)
            exit()
        elif total > x:
            print(i)
            exit()

Solution (Python):
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))

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

if sum(A) < x:
    print(N-1)
else:
    A.sort()
    count = 0
    while(x > 0):
        x -= A[count]
        if x >= 0:
            count += 1
    print(count)

Solution (Python):
N, x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
f=0
i=0
while x>=a[i]:
    x=x-a[i]
    i=i+1
    f=f+1
    if i==N:
        break
if i==N and x>0:
    print(f-1)
else:
    print(f)

Solution (Python):
N, x=map(int, input().split())
a=list(map(int, input().split()))
a.sort()
i=0
while i<N and x>=a[i]:
  x-=a[i]
  i+=1
if i==N and x>0:
  i-=1
print(i)

Solution (Python):
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)

Solution (Python):
N, x = map(int, input().split())
array = list(map(int, input().split()))
a = sorted(array, reverse=False)

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

Solution (Python):
N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

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

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

Solution (Python):
import math


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








a.sort()
tot = 0
for i in range(n):
  tot = tot + a[i]
  if(x < tot):
    print(i)
    break

if(x == tot):
  print(i+1)
if(x > tot):
  print(i)

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

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

Solution (Python):
def getInput():
    return [int(i) for i in input().rstrip().split(' ')]

N, x = getInput()
a_i = getInput()
a_i.sort()
child = 0
for i in range(N):
    a = a_i.pop(0)
    if x >= a:
        x = x - a
        if x > 0 and not a_i:
            break
        child += 1
    if x == 0:
        break

print(child)

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

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

A = sorted(a)

ans = 0

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

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

a.sort()
tmp = a[0]
cnt = 0
for i in range(1,n):
    
    if tmp<=x:
        cnt += 1
        tmp += a[i]
    else:
        break
if tmp==x:
    cnt +=1
print(cnt)

Solution (Python):
from sys import stdin

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))
li.sort()
count = 0
for i in range(n-1):
    if li[i] <= m:
        count += 1
        m -= li[i]
if li[-1] == m:
    count += 1
print(count)

Solution (Python):
N, x = map(int, input().split())
a_list = list(map(int, input().split()))


ans = 0
a_list.sort()

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

if x > 0 and ans == N:
    ans -= 1

print(ans)

Solution (Python):
import itertools
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
a = list(itertools.accumulate(a))
cnt = 0
for i in range(n):
    if i==n-1 and a[-1]!=x:
        pass
    elif a[i]<=x:
        cnt+=1
print(cnt)

Solution (Python):
n, x = list(map(int, input().split()))
lista = list(map(int, input().split()))

lista.sort()

snack = 0

for i in range(n):
  if lista[i] + snack <= x:
    snack += lista[i]
  else:
    print(i)
    break
else:
  if snack == x:
    print(n)
  else:
    print(n - 1)

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

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


a = sorted(a)

leftCandy = x
childrenCnt = 0
for i in range(len(a)):
  leftCandy -= a[i]
  if leftCandy >= 0:
    childrenCnt += 1

if leftCandy > 0:
  childrenCnt -= 1

print(childrenCnt)

Solution (Python):
N,x = map(int,input().split())
li = list(map(int,input().split()))

newLi = sorted(li)
ans = 0

for i in range(len(newLi)):
  if x - newLi[i] < 0:
    break
   
  if i == (len(newLi) - 1) and x != newLi[i]:
    break
  
  x -= newLi[i]
  ans += 1

print(ans)

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

a.sort()

rem = x
give = 0

for i in range(n):
    rem -= a[i]
    give += 1
    if rem < 0:
        break

if rem != 0:
    give -= 1

print(give)

Solution (Python):
n, x = map(int, input().split())
ls = list(map(int, input().split()))

ans = 0
m = x

ls.sort()

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

if m > sum(ls):
    print(ans - 1)
else:
    print(ans)

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

cont = 0

for i in sorted(a):
    x -= i
    if x >= 0:
        cont += 1
    else:
        break

if x > 0:
    cont -= 1

print(cont)

Solution (Python):
N,x = map(int,input().split())
A = sorted(list(map(int,input().split())))
cnt = 0
tot = A[0]
while cnt<N and tot<=x:
    cnt += 1
    if cnt<N:
        tot += A[cnt]
if cnt==N and tot<x:
    cnt -= 1
print(cnt)

Solution (Python):
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))
cnt = 0
for i in range(n):
	k -= a[i]
	if k >= 0:
		cnt += 1
	else:
		break
if k > 0:
	cnt -= 1

print(cnt)

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

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10


def solve():
    n, x = LI()
    a = LI()
    a.sort()
    ans = 0
    for ai in a:
        x -= ai
        if x < 0:
            print(ans)
            return
        ans += 1
    print(ans - (x != 0))
    return



if __name__ == '__main__':
    solve()

Solution (Python):
n,x = map(int,input().split())
al = list(map(int,input().split()))

al = sorted(al)
for idx, a in enumerate(al):
   if x >= a:
      x -= a
   else:
      print(idx)
      import sys
      sys.exit()
if x > 0:
   print(n-1)
else:
   print(n)

Solution (Python):
from itertools import accumulate
from bisect import bisect_right

N, x, *A = map(int, open(0).read().split())

A.sort()
S = list(accumulate(A))

if S[-1] == x:
    print(N)
else:
    print(min(N - 1, bisect_right(S, x)))

Solution (Python):
from itertools import accumulate
from bisect import bisect_right

N, x, *A = map(int, open(0).read().split())

A.sort()
S = list(accumulate(A))

if S[-1] == x:
    print(N)
else:
    k = bisect_right(S, x)
    print(N - 1 if k == N else k)

Solution (Python):
from sys import stdin, exit
import itertools


if __name__ == "__main__":
    N, K = [int(item) for item in stdin.readline().split()]
    li = [int(item) for item in stdin.readline().split()]
    
    li.sort()
    
    if sum(li) == K:
        print(N)
    elif sum(li) < K:
        print(N-1)
    else:
        cumsum = itertools.accumulate(li)
        index = [i for i, item in enumerate(cumsum) if item<=K]
        print(len(index))

Solution (Python):

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

tmp = 0
A_1  = x
for i in range(N):
    A_1 = A_1 - a[i]
    if A_1 > 0:
        if i == N-1:
            print(tmp)
            exit()
        else:
            tmp += 1
    elif A_1 == 0:
        tmp += 1
        print(tmp)
        exit()

    else:
        print(tmp)
        exit()
print(tmp)

Solution (Python):
n,x=map(int, input().split())
l=sorted(list(map(int, input().split())))
ans=0
if x==sum(l):
  print(n)
elif x>sum(l):
  print(n-1)
else:
  for i in range(n):
    if x>=l[i]:
      ans+=1
      x=x-l[i]
    else:
      print(ans)
      exit()

Solution (Python):
import sys
import numpy as np

stdin = sys.stdin

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

N, x = rl()
A = rl()
A.sort()
A = np.array(A)
A_cum = A.cumsum()
answer = 0
if A_cum[-1] < x:
    answer = N - 1
for i in range(N):
    if A_cum[i] == x:
        answer = i+1
        break
    elif A_cum[i] > x:
        answer = i
        break
        
print(answer)

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from bisect import bisect_right
import itertools

N,X,*A = map(int,read().split())

A.sort()
Acum = list(itertools.accumulate(A))

answer = bisect_right(Acum,X)
if answer == N:
    if Acum[-1] < X:
        answer -= 1
print(answer)

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

a.sort()
cnt=0
for i in range(N):
    if i==N-1:
        if x==a[i]:
            cnt+=1
    elif x>=a[i]:
        x=x-a[i]
        cnt+=1
print(cnt)

Solution (Python):
N, x = map(int,input().split())
a = [int(_) for _ in input().split()]
s = sum(a)
a.sort()
cnt = 0
for i in range(N):
    if x >= a[i]:
        cnt += 1
        x -= a[i]
    elif x > 0:
        x -= max(x,a[i])
if x > 0:
    cnt -= 1
print(cnt)

Solution (Python):
n,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
if a[0]>x:
    print(0)
    exit()
cnt=1
for i in range(1,n):
    a[i]+=a[i-1]
    if a[i]>x:
        break
    cnt+=1
if cnt==n and a[-1]!=x:
    cnt-=1
print(cnt)

Solution (Python):

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

n, ans = 0, 0
for i in range(N):
    if n + A[i] <= x:
        n += A[i]
        ans += 1
    else:
        break

if n < x and ans == N:
    print(ans - 1)
else:
    print(ans)

Solution (Python):
n,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
if a[0]>x:
    print(0)
    exit()
cnt=1
for i in range(1,n):
    a[i]+=a[i-1]
    if a[i]>x:
        break
    cnt+=1
if cnt==n and a[-1]!=x:
    cnt-=1
print(cnt)

Solution (Python):
n,c=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
for i in range(n):
  if a[i]>c:
    print(i)
    break
  else:
    c-=a[i]
else:
  if c>0:
    print(n-1)
  else:
    print(n)

Solution (Python):
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)

Solution (Python):
N, x = list(map(int, input().split()))
li = sorted(list(map(int, input().split())))
res = 0
for i  in li:
    x -= i
    if x < 0:
        break
    else:
        res += 1
if x > 0:
    res -= 1

print(res)

Solution (Python):
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)

Solution (Python):
N, x = map(int, input().split())
a = [int(i) for i in input().split()]

if sum(a) == x :
  print(N)
else :
  a.sort()
  s = 0
  for i in range(N) :
    if s + a[i] > x :
      break
    s += a[i]

  print(i)

Solution (Python):
n,x = map(int, input().split())
a = [int(i) for i in input().split()]

a.sort()
ans = 0

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

if x >0 :
    ans-=1
print(ans)

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

a.sort()
ans = 0

for i in range(n):
    if a[0] < x :
        ans += 1
        x -= a[0]
        a.pop(0)
    else:
        if x in a:
            ans += 1
        x = 0
        break
if x != 0:
    ans -= 1
print(ans)

Solution (Python):

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

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

if ans == 0:
	print(ans)
elif x == 0:
	print(ans)
else:
	print(ans-1)

Solution (Python):

import sys
import itertools
import math

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











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




child_il=sorted(child_i)

i=0
j=0
for i in range(N):
 x=x-child_il[i]
 if x < 0:
    print(j)
    sys.exit()
 elif i==N-1 and x!=0:
    break 
 else:
     j=j+1

print(j)

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

a = sorted(a)

ans = 0

for i in range(n):
	if x >= a[i]:
		ans = ans + 1
		x = x - a[i]
	else:
		pass
	
if ans == n and x != 0:
	ans = ans - 1	
	
print(ans)

Solution (Python):
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)

Solution (Python):


def main()->None:
    (N, x) = map(int, input().split())
    a = list(map(int, input().split()))
    sorted_a = sorted(a) 
    count = 0 
    for d in sorted_a:
        x -= d
        if x < 0:
            break
        count += 1
    
    if x > 0:
        print(count-1)
    else:
        print(count)

if __name__ == "__main__":
    main()

Solution (Python):


def main()->None:
    (N, x) = map(int, input().split())
    a = list(map(int, input().split()))
    sorted_a = sorted(a) 
    count = 0 
    for d in sorted_a:
        x -= d
        if x < 0:
            break
        count += 1
    
    if (count == N) and (x > 0):
        print(count-1)
    else:
        print(count)

if __name__ == "__main__":
    main()

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

A.sort()

y, i = 0, 0
while y < x and i < N:
  y += A[i]
  i += 1
if y > x or (y < x and i == N):
  i -= 1
print(i)

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

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

a.sort()
goukei = 0
count = 0

if sum(a) < x:
    count = n-1
elif sum(a) == x:
    count = n
else:
    for i in range(n):
        goukei += a[i]
        if goukei > x:
            break
        else:
            count += 1

print(count)

Solution (Python):
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)

Solution (Python):
import sys

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

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

s = 0
for i in range(N):
    s += a[i]

    if s == x:
        print (i + 1)
        sys.exit()

    elif s > x:
        print (i)
        sys.exit()

print (N-1)

Solution (Python):
n,x,*a=map(int,open(0).read().split())
a.sort()
b,c=0,0
for i in a:
    if b+i<=x:
        b+=i
        c+=1
print(c-1*(sum(a)<x))

Solution (Python):

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

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

if x == a[-1]:
    ans += 1

print(ans)

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

if x>0:
    c-=1
print(c)

Solution (Python):
N,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
count = 0
i = 0
while x > count:
    if i == N:
        break
    count += a[i]
    i += 1

if x == count:
  print(i)
else:
  print(i-1)

Solution (Python):
n, x = map(int, input().split())
a = list(map(int, input().split()))
a_asc = sorted(a)
ans = 0
for i in range(n):
    x -= a_asc[i]
    if x >= 0:
        ans += 1
print(ans - 1 if x != 0 and x > 0 else ans)

Solution (Python):
import bisect
from itertools import accumulate
n, x = map(int, input().split())
A = sorted(list(map(int, input().split())))
L = list(accumulate(A))
if L[-1] < x:
  print(n-1)
else:
  print(bisect.bisect_right(L, x))

Solution (Python):
n, x = map(int, input().split())
*a, = sorted(map(int, input().split()))

ans = 0
for i in range(len(a)):
    x -= a[i]
    if x >= 0:
        ans += 1

print(ans - 1 if x != 0 and x > 0 else ans)

Solution (Python):
N,x=map(int,input().split())
A=sorted(list(map(int,input().split())))
ans=0
for i in range(len(A)):
  if x>=A[i]:
    x-=A[i]
    ans+=1
  else:
    break
else:
  if x>0:
    ans=max(ans-1,0)
print(ans)

Solution (Python):
N, x = map(int, input().split())
array = list(map(int, input().split()))

array.sort()
s = sum(array)

if s < x:
    print(N-1)
elif s == x:
    print(N)
else:
    a = 0
    for i in range (N):
        a += array[i]
        if a > x:
            print(i)
            break

Solution (Python):
n, x = map(int, input().split())
a = sorted(list(map(int, input().split())))

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

print(ans)

Solution (Python):
n,x = map(int,input().split())
suma = 0
ans = 0
for a in sorted(list(map(int,input().split()))):
  if suma + a == x:
    print(ans+1)
    exit()
  elif suma + a > x:
    print(ans)
    exit()
  else:
    suma += a
    ans += 1
print(ans if suma>=x else ans-1)

Solution (Python):
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)