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


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

children.sort()

count = 0
index = 0

for c in children:
    
    is_last_child = index + 1 == len(children)
    if is_last_child:
        if x == c:
            x -= c
            count += 1
    elif x >= c:
        x -= c
        count += 1
    index += 1

print(count)

Solution (Python):
import sys
N, x = map(int, sys.stdin.readline().rstrip().split())
aa = sorted(list(map(int, sys.stdin.readline().rstrip().split())))
cnt = 0
for a in aa:
    x -= a
    if x < 0: break
    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()
counter = 0
while x > 0 and counter <= len(a)-1:
  if len(a) - 1 > counter and x >= a[counter]:
    x -= a[counter]
    counter += 1
  elif len(a) - 1 == counter and x == a[counter]:
    x = 0
    counter += 1
  else:
    x = 0

print(counter)

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

y=x

array.sort()

cnt = 0
for i in range(n):
  x -= array[i]
  if x >= 0:
    cnt += 1
    
if cnt == n and sum(array) !=y:
  cnt = cnt-1
    
print(cnt)

Solution (Python):
nx = input().split()
n = int(nx[0])
x = int(nx[1])
a = input().split()
for i in range(n):
	a[i] = int(a[i])

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

if x == a[n-1]:
	c += 1
	
print(c)

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

Solution (Python):
import itertools

N, x = [int(y) for y in input().split(' ')]
arr = sorted([int(y) for y in input().split(' ')], reverse=False)
cumsum = list(itertools.accumulate(arr))

ret = 0
p = True

for csum in cumsum:
  if csum > x:
    print(ret)
    p = False
    break
    
  ret += 1

if p: 
  print(ret) if cumsum[len(cumsum) - 1] == x else print(ret - 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 a[i] <= x:
        ans += 1
        x -= a[i]
        if i == N - 1 and x != 0:
            ans -= 1
    
print (ans)

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

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

Solution (Python):
n,x=list(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=count+1
if(x>0):
  count=count-1
print(count)

Solution (Python):

import sys, math, fractions, itertools, collections, copy, heapq


def solve(N: int, x: int, a: "List[int]"):
    a.sort()
    res = 0
    xx = x
    for i in range(N):
        if x >= a[i]:
            res += 1
            x -= a[i]
        else:
            x = 0
    if x > 0:
        res -= 1
    print(res)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    x = int(next(tokens))  
    a = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, x, a)

if __name__ == '__main__':
    main()

Solution (Python):
_, X = map(int, input().split())
A = sorted(list(map(int, input().split())))

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

if count == len(A) and X > 0:
    count -= 1

print(count)

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

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

Solution (Python):
from itertools import accumulate
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
a_acc = list(accumulate(a))
for i in range(n):
    if a_acc[i] > x:
        print(i)
        exit()
if sum(a) == x:
    print(n)
else:
    print(n-1)

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

A.sort()
ans = 0
looped = True
for a in A:
    if x < a:
        looped = False
        break
    x -= a
    ans += 1

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

print(ans)

Solution (Python):
N, X = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
result = 0

for i in range(N):
    X -= A[i]
    if X <= 0:
        if X == 0:
            result = i+1
        else:
            result = i
        break

if X > 0:
    result = N-1

print(result)

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

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

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

if x == a[N-1]:
  count += 1
    
    
print(count)

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

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

if sum(a) == x:
    print(n)
else:
    a.sort()
    s = 0
    for i,v in enumerate(a):
        s += v
        if s > x:
            print(i)
            exit()
    print(n-1)

Solution (Python):
mans, nums = map(int,input().split())
req_array  = sorted(list(map(int,input().split())))
count = 0

for i in range(mans):

    if ( i +1 ) == mans and nums == req_array[i]:
        count += 1
        nums -= req_array[i]
    elif ( i +1 ) == mans:
        break

    if nums >= req_array[i]:
        count += 1
        nums -= req_array[i]
    else:
        break
print(count)

Solution (Python):
n, x = map(int, input().split())
an = list(map(int, input().split()))
c = 0
for i in sorted(an):
    if x >= i:
        x -= i
        c += 1
    else:
        print(c)
        exit()
if x > 0:
    print(c - 1)
else:
    print(c)

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

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

al.sort()

count=0

for i in range(n) :
  d=x-al[i]
  if d<0 :
    break
  
  if i==n-1 and d>0 :
    break
  
  x=x-al[i]
  
  count+=1
print(count)

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

Solution (Python):
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:
    if x == 0:
        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,a in enumerate(A):
    if i<n-1:
        if x>=a:
            ans+=1
            x-=a
        else:
            break
    else:
        if x==a:
            ans+=1
        else:
            break
print(ans)

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

i = 0
ans = 0
while x > 0 and i<= n-1:
  if x >= l[i]:
    x -= l[i]
    if i == n-1:
      if x == 0:
        ans += 1
        break
      else:
        break
    else:
      i += 1
      ans += 1
  else:
    x = 0
    break
print(ans)

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

Solution (Python):

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

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

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

for _ in range(n):
    if x >= happy_lists[_]:
        if _ == len(happy_lists)-1:
            if x == happy_lists[_]:
                happy_children += 1
        else:
            happy_children += 1
            x -= happy_lists[_]

print(happy_children)

Solution (Python):

N, X = map(int, input().split())
a = sorted(list(map(int, input().split())))
count = 0
for i in range(N):
    if X >= a[i]:
        count += 1
        X = X - a[i]
    else:
        break
if count == N and X > 0:
    count -= 1  
print(str(count))

Solution (Python):
N,x,*a = map(int, open(0).read().split())

if sum(a) == x:
  print(N)
  exit()
  
cnt = 0
for i, a_ in enumerate(sorted(a)):
  x -= a_
  if 0 <= x:
    cnt += 1
  else:
    break
print([cnt,cnt-1][0<x])

Solution (Python):
N,x,*a = map(int, open(0).read().split())
cnt = 0
for i, a_ in enumerate(sorted(a)):
  x -= a_
  if not i == len(a)-1:
    if 0 <= x:
      cnt += 1
    else:
      break
  else:
    if x == 0:
      cnt += 1
    else:
      break
print(cnt)

Solution (Python):
n, x = map(int, input().rstrip("\n").split())
kids_needs = sorted(list(map(int, input().rstrip("\n").split())))

c = 0
for need in kids_needs:
    x -= need
    if x < 0:
        break
    c += 1
else:
    c -= bool(x)

print(c)

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

a_list = list(map(int, input().split()))
a_list.sort()
give = 0
count = 0

for num in a_list:
    give += num
    if give == x:
        count += 1
        break
    if give > x:
        count -= 1
    count += 1

if give < x:
    count -= 1

print(count)

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

a_sort = sorted(a)

for i in range(N):
    x -= a_sort[i]
    if x < 0 or (x > 0 and i == N-1):
        print(i)
        break
    elif x == 0:
        print(i + 1)
        break

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


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

memolist = [0]*(N+1)

import copy

for child in a:
    nextmemolist = copy.copy(memolist)
    for i in range(len(memolist)):
        if (memolist[i] + child) <= x and ((memolist[i] + child) < memolist[i+1] or memolist[i+1] == 0):
            nextmemolist[i+1] = memolist[i] + child
        if memolist[i+1] == 0:
            break
    memolist = nextmemolist


if memolist[-1] == x:
    print(N)
elif memolist[-1] != 0:
    print(N-1)
else:
    for i, ans in enumerate(memolist):
        if i == 0:
            continue
        if ans == 0:
            print(i-1)
            break

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

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

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

Solution (Python):

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

a.sort()

b = 0
count = 0

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

print(count)

Solution (Python):
from bisect import bisect
from itertools import accumulate
n,x,*a=map(int,open(0).read().split())
b=list(accumulate(sorted(a)))
print(bisect(b,x)-(b[-1]<x))

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

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

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

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

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

Solution (Python):
n, x = list(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):
import sys
sys.setrecursionlimit(100000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from copy import *

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

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

a.sort()


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

Solution (Python):


from itertools import accumulate


def main():
    
    n, x = tuple(map(int, input().rstrip().split()))
    A = sorted(map(int, input().rstrip().split()))
    ac = list(accumulate(A))
    if ac[-1] < x:
        ans = n - 1
    else:
        ans = sum(i <= x for i in ac)
    print(ans)


if __name__ == "__main__":
    main()

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

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

a.sort()

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()))
A.sort()
cnt =0
for i in range(N-1):
    if x<A[i]:
        break
    else:
        x = x-A[i]
        cnt += 1

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

Solution (Python):
a, b = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
d = 0
for i in c:
    b -= i
    d += 1
    if b < 0:
        break
if b != 0:
    d -= 1
print(d)

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

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

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

a_s = sorted(a)

count=0
if sum(a) < x:
  count = -1
for i in range(N):
  if a_s[i] <= x:
    count += 1
    x -= a_s[i]
print(count)

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

a_s = sorted(a)

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

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

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

for i in range(len(a)):
    if sum(a) == x:
        while n > 0:
            count += 1
            n -= 1
        continue
    remain -= a[i]
    if remain >= 0 and i != len(a)-1:
        count += 1
    else:
        break

print(count)

Solution (Python):
N,x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a_sorted = sorted(a)
num =0
x_num = x
for i in range(N):
    if(x_num - a_sorted[i] >= 0):
        x_num -= a_sorted[i]
        num += 1
        if(i == N-1 and x_num >0):
            num -= 1
    else:
        break
print(num)

Solution (Python):
a, b = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
e = 0
f = 0
for i in c:
    e += i
    f += 1
    if e >= b:
        break
if e != b:
    f -= 1
print(f)

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

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

Solution (Python):
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
    
n,x=MI()
a=LI()
a.sort()
y=x
ans,s=0,0
for i in range(n):
    s+=a[i]
    if s>x:
        break
    else:
        if i<n-1:
            ans+=1
        elif x-s==0:
            ans+=1
            
print(ans)

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

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

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

a_list.sort()

def func():
    cnt = 0
    global x
    for a in a_list:
        if x>=a:
            x -= a
            cnt += 1
        else:
            return cnt
    if x==0:
        return cnt
    else:
        return cnt-1

print(func())

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

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

if x <= 0:
    print(cnt)
else:
    print(cnt - 1)

Solution (Python):

from collections import defaultdict, deque
import math
from math import factorial
import fractions
import re

BIGNUM = 10 ** 9 + 7

def main():
    N, x = map(int, input().split())
    As = list(map(int, input().split()))

    As = sorted(As)
    total = 0
    num = 0
    for a in As:
        if total+a <= x:
            total += a
            num += 1
        else:
            break

    if num == N and total != x:
        num -= 1
    print(num)

if __name__ == '__main__':
    main()

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

ans = 0
A.sort()
i = 0
while i < N and x > 0:
    if x >= A[i]:
        if i != N-1 or x == A[i]:
            ans += 1
        x -= A[i]
    else:
        break
    i += 1

print(ans)

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

ans = 0
A.sort()
i = 0
while i < N and x > 0:
    if x >= A[i]:
        if i != N-1 or x == A[i]:
            ans += 1
        x -= A[i]
    else:
        break
    i += 1

print(ans)

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

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

a.sort()

c = 0
sum = 0
for b in a:
    if sum + b <= x:
        c += 1
        sum += b
    else:
        break
if c == N and sum != x:
    c -= 1
print(c)

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

count = 0
for i in range(n):
    x -= sorted(a_list)[i]
    if i < n - 1 and x >= 0:
        count += 1
    elif i == n - 1 and x == 0:
        count += 1

print(count)

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

s = sum(a)
if x == s:
    print(N)
else:
    for i in range(N):
        s -= a[i]
        if x >= s:
            print(N-i-1)
            exit()

Solution (Python):



def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, typ=int):
    return [typ(input()) for _ in range(n)]


def main():
    n, x = read_h()
    a = sorted(read_h())

    cnt = 0
    rem = x
    for ai in a:
        rem -= ai
        if rem < 0:
            break
        cnt += 1

    if rem > 0:
        cnt -= 1

    print(cnt)


if __name__ == '__main__':
    main()

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

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

Solution (Python):
import numpy as np
row = input().split()
N = int(row[0])
x = int(row[1])

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

if x <= 0:
    print(count)
else:
    print(count-1)

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

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

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

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

print(cnt)

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

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

a.sort()


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

if now==0:
    print(cnt)
else:
    print(cnt-1)

Solution (Python):
n,x = map(int,input().split())
a = list(map(int,input().split()))
a_sorted = sorted(a)
total = 0
happy = 0
for v in a_sorted[:-1]:
  total += v
  if total <= x:
    happy += 1 
if sum(a) == x:
  happy = len(a)
print(happy)

Solution (Python):

import sys


def solve(N: int, x: int, a: "List[int]"):
    ans = 0
    a.sort()
    for i in a:
        if(x-i >= 0):
            ans += 1
            x -= i
        else:
            break
    else:
        if(x > 0):
            print(ans-1)
            exit()

    print(ans)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    x = int(next(tokens))  
    a = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, x, a)

if __name__ == '__main__':
    main()

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

a.sort()

cnt = 0

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

        

print(cnt)

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

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

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

if sum(a) < x:
  ans=n-1
elif  sum(a) == x:
  ans=n
else:
  i=0
  val=0
  while val <= x:
    val+=a[i]
    i+=1

  ans=i-1
  
print(ans)

Solution (Python):
n, x = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
num = 0
if sum(a) < x:
    print(n-1)
elif a[-1] > x:
    print(0)
else:
    while x > 0:
        x = x - a.pop()
        if x >= 0:
            num += 1
    print(num)

Solution (Python):
import numpy as np
N,x = map(int,input().split())
A = np.array(input().split(), dtype = np.int64)
A.sort()
np.cumsum(A, out = A)
answer = (A <= x).sum()

if answer == N and A[-1] != x:
  answer -= 1
print(answer)

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

Solution (Python):
n, x = map(int, input().split())
a = list(map(int, input().split()))
num = len(a)
a.sort(reverse=True)
for i in range(num):
    x -= a.pop()
    if x < 0:
        print(i)
        exit()
    if x == 0:
        print(i + 1)
        exit()
print(num - 1)

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


if __name__ == "__main__":
    main()

Solution (Python):
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 x < s:
    break
if x == s:
  print(n)
else:
  print(i)

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


a_sort = sorted(a)

manzoku =0
flag = 0
for n,i in enumerate(a_sort):
    if x>=i:
      x-=i
      
      manzoku+=1

    elif x<i:
      flag =1
      
    

if  flag:
    print(manzoku)
elif flag==0 and(x>0) and (manzoku>0):
    print((manzoku)-1)
else:
    print(manzoku)

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 a[i] <= x:
        cnt += 1
    x -= a[i]

if x > 0:
    cnt -= 1

print(max(0, cnt))

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

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

Solution (Python):

"""
A - Candy Distribution Again
https://atcoder.jp/contests/agc027/tasks/agc027_a

"""
import sys


def solve(N, x, A):
    ans = 0
    for a in A:
        if x >= a:
            ans += 1
            x -= a
    if ans == N and x != 0:
        return ans-1
    return ans


def main(args):
    N, x = map(int, input().split())
    A = sorted([int(a) for a in input().split()])
    ans = solve(N, x, A)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
N, x = map(int,input().split())
A = sorted(list(map(int, input().split())))
ans = 0
su = 0
for i, A_i in enumerate(A):
	if su + A_i <= x:
		ans = i + 1
		su += A_i
	else:
		break
if sum(A) < x:
	ans -= 1
print(max(0, ans))

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

a.sort()
max = 0
for i in range(1, N + 1):
  if sum(a[:i]) <= x:
    max = i
if sum(a[:N + 1]) < x:
  print(N - 1)
else:
  print(max)

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

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

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

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

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

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

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

A.sort()

for i in range(N):
    sum_s += A[i]
    if sum_s > x:
        s = i
        break

if sum_s < x:
    print(N - 1)
elif sum_s == x:
    print(N)
else:
    print(s)