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

def main():
  N, x = map(lambda i: int(i), input().split(' '))
  a = list(map(lambda i: int(i), input().split(' ')))
  a.sort()
  answer = 0
  for i in range(N):
    if x >= a[i]:
      x -= a[i]
      answer += 1
    else:
      print(answer)
      sys.exit()
  print(answer if x == 0 else answer - 1)

main()

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

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

Solution (Python):

import sys, math
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans=count=0

n,x=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
for i in range(n-1):
    ai=A[i]
    if x>=ai:
        x-=ai
        count+=1
if A[n-1]==x:
    count+=1
print(count)

Solution (Python):
n, x = [int(x) for x in input().split()]
children = [int(x) for x in input().split()]
children.sort()
for i, child in enumerate(children):
    if x < child or (i==len(children)-1 and x!=child):
        print(i)
        break
    else:
        x -= child
else:
    print(len(children))

Solution (Python):

N, x = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
ans = 0
cnt = 0
if x > sum(A):  
    print(N-1)
    exit()
if x == sum(A): 
    print(N)
    exit()
if x < A[0]:    
    print(0)
    exit()

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

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

l = sorted([int(i) for i in input().split()])
total = sum(l)

if total == m:
    print(n)
elif total < m: 
    print(n-1)
else:
    ct = 0
    for i in l:
        if m >= i:
            ct += 1
            m -= i
        else:
            break
    print(ct)

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

print(cnt)

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

li.sort()
ans = 0

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

Solution (Python):
import math
import heapq
import sys
from collections import Counter




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

heapq.heapify(a)  

for i in range(N):
    x-=heapq.heappop(a)  
    
    if x<=0 or i==N-1:
        if x==0:
            print(i+1)
        else:
            print(i)
        break

Solution (Python):


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

a_list = [a for a in a_list if a <= x]
count = 0
d_list = [0] * N


for i, a in enumerate(a_list):
    if i == N - 1:
        
        d_list[i] = x
        break

    if x - a >= 0:
        d_list[i] = a
        x -= a
    else:
        d_list[i] = x
        break

ans = len([a for a, d in zip(a_list, d_list) if a == d])

print(ans)

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

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

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

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 bisect
import itertools
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n, x = ril()
ls = sorted(ril())
acc = list(itertools.accumulate(ls))
i = bisect.bisect(acc, x)
if i == len(acc):
    if x > acc[-1]:
        i -= 1
print(i)

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

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

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

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

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

    a.sort()

    i = 0
    while i < n - 1 and x >= a[i]:
        x -= a[i]
        i += 1

    if i == n - 1 and a[i] == x:
        i += 1

    print(i)


if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,x = inpl()
a = inpl()
a.sort()
if sum(a) < x:
    print(n-1)
else:
    s = 0
    for i,y in enumerate(a):
        
        if s + y < x:
            s += y
        elif s + y == x:
            print(i+1)
            break
        else:
            print(i)
            break
    else:
        print(n-1)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,x = inpl()
a = inpl()
a.sort()
if a[0] > x:
    print(0)
elif sum(a) == x:
    print(n)
elif sum(a) < x:
    print(n-1)
else:
    s = 0
    for i,y in enumerate(a):
        
        if s + y < x:
            s += y
        elif s + y == x:
            print(i+1)
            break
        else:
            print(i)
            break
    else:
        print(n-1)

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

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

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

print(ans)

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

tmp_total_a = 0
count_happy = 0
for a in a_list:
    tmp_total_a += a
    if tmp_total_a <= x:
        count_happy += 1
    else:
        break

if tmp_total_a < x:
    count_happy -= 1
    
print(count_happy)

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

count = 0
for i in sorted(a):
    if x >= i:
        x -= i
        count += 1
    
    
if x > 0 and count == n:
    count -= 1
print(count)

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

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

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

print(r)

Solution (Python):
def main():
    N, x = (int(i) for i in input().split())
    a = [int(i) for i in input().split()]
    a.sort()
    ans = 0
    i = 0
    while x > 0:
        if i < N - 1 and x - a[i] >= 0:
            x -= a[i]
            ans += 1
        elif i == N-1 and x == a[i]:
            x -= a[i]
            ans += 1
        else:
            break
        i += 1
    print(ans)


if __name__ == '__main__':
    main()

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

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

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

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

a_L = list(sorted(a_L))

counter = 0
for val in range(n):
    if x - a_L[val] >= 0 and val != n-1:
        counter += 1
        x = x-a_L[val]

    if x - a_L[val] == 0 and val == n-1:
        counter +=1
        break

print(counter)

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

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

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

a.sort()

ans=0

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

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

for ai in a:
    sum_a+=ai
    if sum_a<=x:
        ans+=1

if sum_a<x:
    ans-=1

print(ans)

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

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

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

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

A.sort()
s = 0
ans = 0
while ans < n and s <= x:
    s += A[ans]
    ans += 1

if s != x:
    ans -= 1
print(ans)

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

Solution (Python):


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

count=0
while len(A)>1:
    temp=A.pop(-1)
    if temp>x:
        break
    else:
        count+=1
        x-=temp

temp=A.pop(-1)

if x==temp:
    print(count+1)
else:
    print(count)

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

for A in a:
    if x >= A:
        c += 1
        x -= A
if c == N and x != 0:
    c -= 1
print(c)

Solution (Python):
N, X = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
last_index = len(A) - 1
ret = 0
for i, a in enumerate(A):
    if a <= X:
        ret += 1
        X -= a
if ret == N and X > 0:
    ret -= 1
print(ret)

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

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

a.sort()
ans = 0

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

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

ans=0
b=True
for i in range(N):
  if x-a_sort[i]>=0:
    x-=a_sort[i]
    ans+=1
  else:
    b=False
    break

if b and x>0:
  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:
    diff=sum(a)-x
    a.sort(reverse = True)
    cnt=0
    while diff > 0 and cnt < n:
        diff -= a[0+cnt]
        cnt+=1
    print(n-cnt)

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

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

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

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

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

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

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

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

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

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]:
    x-=A[i]
    ans+=1
  else:
    break
  if i==N-1 and x>0:
    ans-=1
print(ans)

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

Solution (Python):
N, x = tuple(map(int, input().split()))
A = list(map(int, input().split()))
A = sorted(A)
count = 0
for a in A[:-1]:
    if a <= x:
        count += 1
        x -= a

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

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

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

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

print(ans)

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n, x = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    a.sort()
    cnt = 0
    for v in a:
        x -= v
        cnt += 1
        if x == 0:
            break
        elif x < 0:
            cnt -= 1
            break
    print(cnt if x <= 0 else cnt - 1)


if __name__ == '__main__':
    slove()

Solution (Python):


from itertools import accumulate as acc


def main():
    
    N, X, *A = map(int, open(0).read().split())
    A.sort()
    ac = list(acc(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):
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 and x-a>0:
    break
  elif x-a<0:
    break
  x-=a
  ans+=1
print(ans)

Solution (Python):
N, x = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
m = 0
ans = 0
flag = True
for i in range(N):
  x -= A[i]
  ans += 1
  if x == 0:
    print(ans)
    flag = False
    break
  elif x < 0:
    print(ans-1)
    flag = False
    break
if flag:
  print(ans-1)

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

Solution (Python):
def resolve():
    n, x = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    for i in range(n):
        if x >= a[i]:
            x -= a[i]
            a[i] = 0
    ans = a.count(0)
    if x and all(ai == 0 for ai in a):
        ans -= 1
    print(ans)


if __name__ == "__main__":
    resolve()

Solution (Python):

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


a.sort()

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

print(ans)

Solution (Python):
def solve(n, x, a):
    ans = 0
    for v in sorted(a):
        if v <= x:
            ans += 1
            x -= v
    if (x > 0) and (ans == n):
        ans -= 1
    return ans

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

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

Solution (Python):
def cumsum(inlist):
    s = 0
    outlist = []
    for i in inlist:
        s += i
        outlist.append(s)
    return outlist

n, x = [ int(v) for v in input().split() ]
candy_list = sorted([ int(v) for v in input().split() ])
candy_list_2 = cumsum(candy_list)

ans = 0
for i in range(n):
    if i != n-1 and candy_list_2[i] <= x:
        ans += 1
    elif i == n-1 and candy_list_2[i] == x:
        ans += 1
print(ans)

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

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

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

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

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

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

print(count)

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

Solution (Python):
N,x,*A=map(int,open(0).read().split());A.sort();s=sum(A)
if s==x:print(N)
else:
    W=[0]
    for a in A[::-1]:W+=[W[-1]+a]
    for i,w in enumerate(W[1:],1):
        if w>=s-x:print(N-i);break

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

for A in a:
    if x >= A:
        c += 1
        x -= A
if c == N and x != 0:
    c -= 1
print(c)

Solution (Python):

import os,re,sys,operator,math,heapq,string


from itertools import accumulate,combinations
from sys import stdin,setrecursionlimit


setrecursionlimit(10**6)
input=stdin.readline

n,x=map(int,input().split())
a=sorted([int(i) for i in input().split()])
ans=0
l=0
while x>0 and l<n:
    x-=a[l]
    if x>=0:
        ans+=1
    l+=1
if x>0:
    ans-=1
print(ans)

Solution (Python):
import numpy as np
N, x = map(int,input().split())
b = sorted(list(map(int,input().split())))
a = np.cumsum(b)
if x == sum(b):
    print(N)
    exit()
for i in range(N):
    if x < a[i]:
        print(i)
        exit()
print(N-1)

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


if __name__ == '__main__':
    main()

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

Solution (Python):



import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

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

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

print(ans)

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

remain = x
count = 0

if sum(aList)<x:
  count = N-1
elif sum(aList)==x:
  count = N
else:
  for i in range (N):
      if remain-aList[i] >= 0:
        remain-=(aList[i])
        count += 1

print(count)

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

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

A = sorted(A)

ans = 0

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

Solution (Python):



import heapq

N, x = map(int, input().split())
a = list(map(int, input().split()))
heapq.heapify(a)
tmp = 0
ctr = 0

for i in range(N):
    tmp += heapq.heappop(a)
    if tmp > x or (a == [] and tmp != x):
        print(ctr)
        exit()
    else:
        ctr += 1
else:
    print(ctr)

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

cnt = 0
A.sort()

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

print(cnt)

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

children.sort()

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

Solution (Python):
n, x = map(int, input().split())
arr = map(int, input().split())
count = 0
for m in sorted(arr):
    x -= m 
    if x == 0:
        count += 1
        break
    elif x < 0:
        break
    else:
        count += 1
print(count - 1 if x > 0 else count)

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

if x>0:
    print(i)
elif x==0:
    print(i+1)

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

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

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007


def A():
    n,x = LI()
    a = LI()
    a.sort()
    ans = 0
    for i in a:
        if i <= x:
            ans += 1
            x -= i
        else:
            print(ans)
            return
    if x:
        print(ans-1)
    else:
        print(ans)
    return


def B():
    n,X = LI()
    x = LI()
    for i in range(n-1):
        x[i+1] += x[i]
    x.insert(0,0)
    ans = float("inf")
    f = [5]*(n+1)
    for i in range(1,n):
        f[i+1] = f[i]+2
    for k in range(1,n+1):
        i = 0
        a = n
        d = (k+n)*X
        while a > 0:
            d += f[i]*(x[a]-x[max(0,a-k)])
            a -= k
            i += 1
        ans = min(ans,d)
    print(ans)

def C():
    return


def D():
    return


def E():
    return


def F():
    return



if __name__ == "__main__":
    A()

Solution (Python):
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, x = map(int, input().split())
        a = list(map(int, input().split()))

        a.sort()

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

        print(a.count(0))


if __name__ == '__main__':
    AtCoder().main()

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

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

Solution (Python):
def main():
    N, x = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    i = 0
    count = 0
    while i < N and x-A[i]>=0:
        count += 1
        x -= A[i]
        i += 1
    if x == 0:
        return count
    else:
        if i == N:
            return count - 1
        else:
            return count

if __name__ == '__main__':
    print(main())

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

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

print(ans)

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

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