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 sys

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

c = 0
p = x

for i in range(n-1):
    if a[i] > p:
        print(c)
        sys.exit()
    else:
        c += 1
        p -= a[i]

if a[-1] == p:
    print(n)
else:
    print(n-1)

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

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def SS(): return map(str,sys.stdin.readline().rstrip().split())
def II(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

N,x = II()
a = LI()
a.sort()
cnt = 0
for ai in a:
  if x > ai:
    x -= ai
    cnt += 1
  elif x == ai:
    cnt += 1
    x -= ai
    break
  else:
    cnt += 1
    break
if x != 0:
  cnt -= 1
print(cnt)

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

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

if x>0:
    cnt-=1

print(cnt)

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

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

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

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

a.sort()

sweets=0

ans = 0

for i in range(n):
    sweets += a[i]
    if sweets <= x:
        ans += 1
    else:
        break

if sweets < x:
    print(ans-1)
else:
    print(ans)

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

a.sort()
flg = True
cnt = 0

if sum(a) < x:
  cnt = n - 1
  flg = False
  
while flg:
  for i in range(n):
    if a[i] <= x:
      cnt += 1
      x -= a[i]
    else:
      flg = False
print(cnt)

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


A.sort()
ans = 0
cur = 0
for a in A:
    cur += a
    if cur > x:
        print(ans)
        exit()
    ans += 1
if cur == x:print(N)
else:print(ans-1)

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

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

for i in range(n):
    x-=a[i]
    if x<0:
        print(i)
        break

if x >0:
    print(n-1)
elif x==0:
    print(n)

Solution (Python):
n, x = map(int, input().split())
aaa = list(map(int, input().split()))
aaa.sort()
ans = 0
for a in aaa:
    if x < a:
        break
    ans += 1
    x -= a
else:
    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):
    x -= a[i]
    if x<0 or (i==N-1 and x!=0):
        break
    ans += 1

print(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 not i == len(a)-1:
        if x > a[i]:
            ans += 1
            x = x-a[i]
        elif x == a[i]:
            ans += 1
            break
        else: 
            break
    else:
        if x == a[i]:
            ans += 1
        else:
            pass

print (ans)

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

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

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

print(ans)

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

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

ans = 0

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

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

a.sort()
count = 0
for i in range(len(a)):
    if i < len(a) - 1 and a[i] <= x:
        count += 1
        x -= a[i]
    elif i == len(a) - 1 and a[i] == x:
        count += 1
    else:
        break
print(count)

Solution (Python):
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:
    ans -= 1
    
print(ans)

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




suma = sum(a)

ans = 0
if suma == x:
  ans = n
elif x > suma:
  ans = n -1
else:
  a = sorted(a)
  nokori = x
  for i in a:
    nokori -= i
    if nokori == 0:
      ans += 1
      break
    elif nokori < 0:
      break
    else:
      ans += 1

print(ans)

Solution (Python):
def main():
    n, x = map(int, input().split())
    A = list(map(int, input().split()))

    A_sorted = sorted(A)

    res = 0

    for kids in A_sorted:
        x = x - kids
        
        if x >= 0:
            res += 1
    
    if x > 0:
        print(res - 1)
    else:
        print(res)

if __name__ == '__main__':
    main()

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

print(cnt)

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

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

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

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

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

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

sort_a = sorted(a)
count = 0
if x > sum(a):
  count-=1
for i in sort_a:
  if x >= i:
    count+=1
    x-=i
  else:
    print(count)
    exit()
print(count)

Solution (Python):
def main():
    n, x = map(int, input().split())
    A = list(map(int, input().split()))

    A.sort()

    if sum(A) == x:
        return n

    for i in range(0, n):
        x -= A[i]
        if x < 0:
            break
    ans = i
    return ans


print(main())

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

Solution (Python):
N, X = map(int, input().split())
lists = list(map(int, input().split()))

if X - sum(lists) == 0:
    print(len(lists))
    exit()

count = 0
for num in sorted(lists):
    X -= num
    if X >= 0:
        count += 1

if X < 0:
    print(count)
else:
    print(count - 1)

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


if sum(a_list) == x:
    print(n)
    exit()

ans = 0

for i, a in enumerate(a_list):
    
    if i == len(a_list) - 1:
        break

    if x < a:
        break
    x -= a
    ans += 1

print(ans)

Solution (Python):


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

A = list(map(int,input().split()))
c=0
while X>=min(A):
    if len(A)==1:
        if X==A[0]:
            c+=1
            print(c)
            exit()
        else:
            print(c)
            exit()

    if X>=min(A):
        X-=min(A)
        A.remove(min(A))
        c+=1

print(c)

Solution (Python):
import numpy as np
N, x = map(int, input().split())
a = np.array(list(map(int, input().split())))

cs = np.sort(a).cumsum()

if cs[-1]<x:
    print(N-1)
elif cs[-1]==x:
    print(N)
else:
    print(np.where(cs<=x)[0].shape[0])

Solution (Python):
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n,x=i2()
a=intl()
a.sort()
b=0
for i in range(n):
	x-=a[i]
	if i<n-1:
		if x>=0:
			b+=1
		elif x<0:
			break
	elif i==n-1:
		if x==0:
			b+=1
print(b)

Solution (Python):
import sys

input = sys.stdin.readline

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

if __name__ == '__main__':
    main()

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

Solution (Python):
n, x = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
ans = 0
i = 0
while n > i:
    an = a.pop()
    if x > an:
        x -= an
        ans += 1
    elif x == an:
        x -= an
        ans += 1
        break
    elif x < an:
        x -= an
        break
    i += 1
    if len(a) == 0:
        break
if x > 0:
    ans -= 1
print(ans)

Solution (Python):


import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))

import itertools
def resolve():
    N,X=pin()
    A=lispin()
    A.sort()
    S=list(itertools.accumulate(A))
    
    for i in range(N):
        if S[i]>X:
            print(i)
            return
    if S[-1]<X:print(N-1)
    else:print(N)
        
        


resolve()

Solution (Python):

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

a.sort()

cnt = 0
flg = True
for i in range(n):
    if a[i] <= x:
        x -= a[i]
        cnt += 1
        
    else:
        flg = False
        break
        
if flg and x != 0:
    cnt -= 1
print(cnt)

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

for i in range(N):
    if i == 0:
        s[i] = a[i]
    else:
        s[i] = s[i-1] + a[i]

    if s[i] > x:
        print(i)
        sys.exit()

if s[-1] < x:
    print(N-1)
else:
    print(N)

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

cnt = 0
for a_ in a:
    cnt += 1
    if a_ <= x:
        x -= a_
    elif a_ > x:
        x -= a_
        break
print(cnt if x == 0 else cnt - 1)

Solution (Python):
import numpy as np

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

cnt = 0
for a_ in a:
    cnt += 1
    if a_ <= x:
        x -= a_
    elif a_ > x:
        x -= a_
        break
print(cnt if x == 0 else cnt - 1)

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

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

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

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

if sum(a) < x:
    print(n - 1)
elif sum(a) == x :
    print(n)
else:
    a.sort()
    cnt = 0
    for i in range(n):
        x -= a[i]
        if x < 0:
            print(cnt)
            quit()
        cnt += 1

Solution (Python):
n, x = map(int, input().split())
l = sorted(list(map(int, input().split())))
kids = 0
ans = 0
for i in range(n):
    kids += l[i]
    if kids <= x:
        ans += 1
    else:
        break

if sum(l) >= x:
    print(ans)
else:
    print(ans - 1)

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

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

child = 0
candy = 0

for i in a:
    candy += i
    if candy <= x:
        child += 1

if sum(a) < x:
    child -= 1

print(int(child))

Solution (Python):
N,X=map(int,input().split())
l=list(map(int,input().split()))
L=sorted(l)
kids=0
ans=0
for i in range(N):
  kids+=L[i]
  if kids<=X:
    ans+=1
  else:
    break
    
if sum(L)>=X:
  print(ans)
  
else:
  print(ans-1)

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

Solution (Python):

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

Solution (Python):



import sys





def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(childs, candies, happyNumber):
    result = 0
    happyNumber.sort()
    for ch_i in range(0, childs, +1):
        candies = candies - happyNumber[ch_i]
        if 0 <= candies:  
            result = result + 1
        else:  
            return result
    
    if 0 != candies:
        return result - 1
    return result


if __name__ == "__main__":
    N, x = MI()
    AI = LI()
    print("{}".format(solver(N, x, AI)))

Solution (Python):

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

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

a_l.sort()
count = 0
for val in a_l[:-1]:
    x -= val
    if x < 0:
        break
    count += 1
if x == a_l[-1]:
    count += 1
print(count)

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

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

if x>0:
  ans-=1

print(ans)

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

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

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

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

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


if x == sum(A):
    print(N)
elif x > sum(A):
    print(N-1)
else:
    cnt = 0
    A.sort()
    for a in A:
        if x < a:
            break
        cnt += 1
        x -= a
    print(cnt)

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 i == N-1:
        if x == 0:
            ans += 1
    elif x >= 0:
        ans += 1
print(ans)

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

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

a.sort()
cnt=0

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

if x >0:
    if cnt == 0:
        cnt = 0
    else:
        if cnt == len(a):
            cnt = cnt -1
        
print(cnt)

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

    ans = 0
    for _a in a[:-1]:
        x = x - _a
        if x >= 0:
            ans += 1
    if x == a[-1]:
        ans += 1
    print(ans)


resolve()

Solution (Python):
n, x = map(int, input().split())
a = sorted(list(map(int, input().split())))
if sum(a) < x:
    print(n-1)
    exit()
if sum(a) == x:
    print(n)
    exit()
idx = s = 0
while True:
    s += a[idx]
    if x == s:
        print(idx+1)
        exit()
    if x < s:
        print(idx)
        exit()
    idx += 1

Solution (Python):
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]
    else:
        break
if ans==N:
    if x==0:
        pass
    else:
        ans-=1
print(ans)

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

i = 0

while x >= A[i]:
    x += -A[i]
    i += 1
    if i == N:
        i = (i-1 if x > 0 else i)
        break

print(i)

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

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

a.sort()

if x < a[0]:
	print(0)
	exit()

if sum(a) < x:
	print(n - 1)
	exit()

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

print(cnt)

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

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

Solution (Python):
import numpy as np
N, x = map(int, input().split())
A = np.array(sorted(list(map(int, input().split()))))
cumsum = A.cumsum()

if cumsum[-1] < x:
    print(N - 1)
    exit()

ans = 0
for i in range(N):
    if cumsum[i] <= x:
        ans = i + 1
print(ans)

Solution (Python):
def resolve():
    
    
    
    n, x = list(map(int, input().split()))
    
    
    
    A = list(map(int, input().split()))
    
    

    cnt = 0
    Asort = sorted(A)
    for i in range(n):
        if x >= Asort[i]:
            x -= Asort[i]
            cnt += 1
            if i == n-1 and x > 0:
                cnt -= 1
        else:
            break

    print(cnt)
resolve()

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

a = sorted(a)

count = 0
for i in range(n):
    if x-a[i] >= 0 :
        count+=1
        x = x-a[i]
    elif x-a[i] < 0:
        print(count)
        exit()
    
if not x == 0 :
    print(count-1)    
    exit()
print(count)

Solution (Python):
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, x = list(map(int,_in[0].split(' ')))
    a_arr = list(map(int,_in[1].split(' ')))
    
    a_arr.sort()
    for i in range(N):
        if sum(a_arr[:i+1]) > x:
            cnt = i
            break
        elif sum(a_arr[:i+1]) == x:
            cnt = i+1
            break
    else:
        cnt = N-1
    
    print(cnt)

Solution (Python):
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    n,x = I2()
    a = intl()
    a.sort()
    i = 0
    s = 0
    if sum(a) == x:
        print(n)
        exit()
    if sum(a) < x:
        print(n-1)
        exit()
    while s <= x:
        s += a[i]
        i += 1
    print(i-1)

Solution (Python):



import sys





def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(haveManyPiaceOFCandy, AI):
    result = 0
    AI.sort()
    for j in range(len(AI)):
        haveManyPiaceOFCandy = haveManyPiaceOFCandy - AI[j]
        if haveManyPiaceOFCandy < 0:
            return result
        else:
            result = result + 1
    
    if 0 < haveManyPiaceOFCandy:
        result = result - 1
    return result


if __name__ == "__main__":
    _, X = MI()
    AI = LI()
    print("{}".format(solver(X, AI)))

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

a.sort()
c = 0
i = 0
while(True):
    if(i >= n - 1):
        break
    if(x < a[i]):break
    c += 1
    x -= a[i]
    i += 1
if(x == a[i]):c += 1
print(c)

Solution (Python):
N,x = map(int,input().split())
As = list(map(int,input().split()))
As.sort()
cnt = 0
ans = 0
while x > 0:
    if cnt + 1 == N and x != As[cnt]:
        x = 0
    elif x >= As[cnt]:
        x -= As[cnt]
        ans+=1
    cnt += 1
else:
    print(ans)

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

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

for i in range(n):
    x -= a_sorted[i]
    if x > 0 and i <= n-2:
        c += 1
    elif x == 0:
        c += 1
    else:
        break

print(c)

Solution (Python):
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:
        print(ans)
        break
    ans += 1
else:
    if x==0:
        print(ans)
    else:
        print(ans-1)

Solution (Python):
N,x = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A)
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)

Solution (Python):
N,x=map(int,input().split())
a=sorted(map(int,input().split()))
c=0
if x>sum(a):
  print(N-1)
  exit()

while x>0 and c<=N-1:
  if x-a[c]>=0:
    x-=a[c]
    c+=1
  else:
    break


print(c)

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

S = 0
c = 0

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

Solution (Python):
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n, x = map(int, input().split())
a = readints()
b = sorted(a)
cnt = 0
for i in range(len(b)):
    if b[i] <= x:
        x -= b[i]
        cnt += 1
if cnt == n and x > 0:
    cnt -= 1
print(cnt)

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

A.sort()
S = 0
count = 0

for i in range(N):
  S += A[i]
  
if S < x:
  print(N-1)
  exit()
else:
  for i in range(N):
    b = x - A[i]
    if b > 0:
      count += 1
      x -= A[i]
    elif b == 0:
      count += 1  
      break
    else:
      break
  print(count)

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

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

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

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

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

print(cnt)

Solution (Python):
n, x = map(int, input().split())
li = sorted(map(int, input().split()))
ans = 0
for a in li:
    if x >= a:
        x -= a
        ans += 1
if ans == n and x > 0:
    ans -= 1
print(ans)

Solution (Python):
n, x = map(int, input().split())
a = list(map(int,input().split()))
a.sort()
c = 0
while x-a[c] >= 0:
    x -= a[c]
    c += 1
    if x == 0:
        break
    elif c == n:
        c -= 1
        break
print(c)

Solution (Python):
n, x = map(int, input().split())
a = list(map(int,input().split()))
a.sort()
c = 0
while x-a[c] >= 0:
    x -= a[c]
    c += 1
    if x == 0:
        break
    elif c == n:
        c -= 1
        break
print(c)

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

    if kashi == x :
        print(N - children.count(0))
    else:
        print(N - children.count(0) - 1)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, x = MAP()
A = LIST()

A.sort()
cnt = 0

for a in A:
    
    x -= a
    if x >= 0:
        cnt += 1
    else:
        break

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

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
    elif x >= a[i]:
        x -= a[i]
        ans += 1
    else:
        break

print(ans)

Solution (Python):
from statistics import median


from fractions import gcd
from itertools import combinations 
from collections import deque
from collections import defaultdict
import bisect










import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,x = readInts()
    A = sorted(readInts())
    now = 0
    cnt = 0
    for i in range(n):
        if now + A[i] <= x:
            if i == n-1:
                if now + A[i]== x:
                    cnt += 1
                else:
                    pass
            else:
                now += A[i]
                cnt += 1
        else:
            break
    print(cnt)
if __name__ == '__main__':
  main()

Solution (Python):
import itertools
import bisect
N,x = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
cumsum = list(itertools.accumulate(A))
ans = bisect.bisect_right(cumsum,x)

if ans == N:
  rest = cumsum[-1] - x
  if rest != 0:
    ans -= 1

print(ans)

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