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
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np


def main(n, x, a):
  cnt = 0
  for j, i in enumerate(a):
    x -= i
    if x < 0:
      break
    elif j == n-1 and x > 0:
      break
    cnt += 1
  return cnt

n, x = map(int, readline().split())
a = np.sort(np.array(readline().split(), np.int64))
print(main(n, x, a))

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

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

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

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

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

print(ans)

Solution (Python):
a = input().split()
N = int(a[0])
budget = int(a[1])
b = [int(s) for s in input().split()]
c = sorted(b)
d = int(0)
for i in range(N-1):
  if budget >= c[i]:
    budget = budget - c[i]
    d = d + 1
  else:
    break

if c[N-1] == budget:
    d = d + 1

print(d)

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

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

a.sort()

if sum(a) < x:
    print(N - 1)

elif sum(a) > x:
    ans = 0
    ans_ = 0
    for a in a:
        ans_ += a
        if ans_ > x:
            break
        ans += 1
    print(ans)

elif sum(a) == x:
    print(N)

Solution (Python):
n,x=map(int,input().split())
a=sorted([int(i)for i in input().split()])
res=0
if sum(a)==x:
    res=n
else:
    for i in range(n):
        if sum(a[:i])<=x:res=i
print(res)

Solution (Python):
n,x=map(int,input().split())
a=sorted([int(i)for i in input().split()])
res=0
if sum(a)==x:
    res=n
else:
    for i in range(n):
        if sum(a[:i])<=x:res=i
print(max(0,res))

Solution (Python):
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if sum(a) == x:
    print(n)
    exit()
if sum(a) < x:
    print(n-1)
    exit()
i = n
while sum(a[:i]) > x:
    i -= 1
print(i)

Solution (Python):
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

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

print(min(ans,n-1 if x>0 else n))

Solution (Python):
n,x = map(int,input().split()) 
A= list(map(int,input().split())) 
A.sort()
a_sum=0  
for i in range(n):
    a_sum+= A[i]
    if x<a_sum:
        print(i)
        exit() 

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

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

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

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

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

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

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

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

Solution (Python):



import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 70
20 30 10"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3 10
20 30 10"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """4 1111
1 10 100 1000"""
        output = """4"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """2 10
20 20"""
        output = """0"""
        self.assertIO(input, output)


def resolve():
    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 -= a[i]
            ans += 1
    if a[-1] == x:
        ans += 1
    print(ans)


if __name__ == "__main__":
    
    resolve()

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

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

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

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

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

print(ans)

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

a.sort()
ans = 0

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

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

a = sorted(a)

cnt = 0

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

Solution (Python):
def candy(arr, n, x):
	if sum(arr) == x:
		return n
	arr.sort()
	best = 0
	j = 0
	while(j < n):
		temp = x
		c = 0
		for i in range(j, n-1):
			if arr[i] < temp:
				c += 1
				temp -= arr[i]
			elif arr[i] == temp:
				c += 1
				break
			if i == n - 2:
				if temp == arr[n-1]:
					c += 1
		best = max(best, c)
		j += 1
	return best
n, x = map(int, input().split())
arr = list(map(int, input().split()))
print(candy(arr, n, x))

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

	a.sort()
	a_sum = 0
	ans = 0

	for i in range(N):
		a_sum += a[i]
		ans += 1

		if a_sum > x:
			ans -= 1
			break

		if i == N - 1 and a_sum < x:
			ans -= 1
			break

	print(ans)


  
if __name__ == "__main__":
  	main()

Solution (Python):
N,x = map(int,input().split())
AAA = map(int,input().split())
AA = list(AAA)
AA.sort()
total = 0
count =0
for i in AA:
  total += i
if total == x:
  ans = N
elif total < x:
  ans = N-1
else:
  for i in AA:
    if x >= i:
      x -= i
      count +=1
  ans = count
print(ans)

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

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

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

print(cnt)

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

print(ans)

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

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

a = sorted(a, reverse = False)

count = 0
if sum(a) < x:
    count = N -1
else:
    for i in a:
        x -= i
        if x < 0:
            break
        elif x == 0:
            count += 1
            break
        elif x > 0:
            count+=1

print(count)

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

a_cs = [0] * (n + 1)
for i in range(n):
    a_cs[i + 1] = a_cs[i] + a[i]

idx = bisect_left(a_cs, x)
if idx == n + 1:
    ans = n - 1
elif a_cs[idx] > x:
    ans = idx - 1
else:
    ans = idx
print(ans)

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

a.sort()

A = sum(a)
if x > A:
  print(N-1)

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

Solution (Python):
import math
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 and x >= a[i] or i == N - 1 and x == a[i]:
        ans += 1
        x -= a[i]
print(ans)

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

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

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

Solution (Python):
N,x = input().split()
A = input().split()
a = []
for i in range(int(N)):
  a.append(int(A[i]))
  
a.sort()
X = int(x)
 
idx = 0
while X>0 and idx<int(N):
  X = X-a[idx]
  idx+=1

if X==0:
  idx+=1
  
print(idx-1)

Solution (Python):

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

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

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

    if x == 0:
        break
print(count)

Solution (Python):
import math


def resolve():
    import sys
    input = sys.stdin.readline
    
    
    import heapq  
    nx = [int(x) for x in input().rstrip().split(" ")]
    x = nx[1]
    a_list = [int(x) for x in input().rstrip().split(" ")]

    heapq.heapify(a_list)
    ans = 0
    while len(a_list) > 0:
        a = heapq.heappop(a_list)

        if len(a_list) == 0:
            if(x == a):
                ans += 1
            break
        if x >= a:
            ans += 1
            x -= a
        else:
            break


    print(ans)

if __name__ == "__main__":
    resolve()

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

Solution (Python):
def main():
    N, x = map(int, input().split())
    A = [int(a) for a in input().split()]
    A.sort()

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

        else:
            if A[i] <= x:
                ans += 1
                x -= A[i]
    print(ans)
    
if __name__ == "__main__":
    main()

Solution (Python):
N, x = map(int, input().split())
A = sorted(list(map(int, input().split())))
res = 0
for a in A:
    x -= a
    res += 1
    if x < 0:
        x = abs(x)
        break
    elif x == 0:
        break

print(max(res-1, 0) if x>0 else res)

Solution (Python):
N, X = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
cnt=0
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 = [int(i) for i in input().split()]

res = 0
if x == sum(a):
  res = N
elif x > sum(a):
  res = N -1
else:
  a.sort()
  while x > 0:
    if x >= a[0]: res += 1
    x -= a.pop(0)

print(res)

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

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

Solution (Python):
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, x = inintm()
A = inintl()

A.sort()
ans = 0

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

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

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

print(ans)

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

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

print(cnt)

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

Solution (Python):
def solve():
  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
      continue
    if x>=A[i]:
      ans += 1
      x -= A[i]
  return ans
print(solve())

Solution (Python):
import sys
import collections
import bisect


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


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import accumulate
N, X = [int(x) for x in input().split()]
a = sorted([int(x) for x in input().split()])
p = list(accumulate(a))

result = 0
for i, x in enumerate(p):
  if X < x:
    break
  if i == N-1 and x != X:
    break
  result += 1

print(result)

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

if x < min(A):
    print(0)
    exit()

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

if x > 0:
    ans -= 1

print(ans)

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

if sum(a) > x:
    while sum(a) > x:
        del a[-1]
    print(len(a))
else:
    print(N) if sum(a) == x else print(N-1)

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

a.sort()

res = 0

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

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


print(count)

Solution (Python):
def resolve():
    N, x = map(int, input().split())
    a = list(map(int, input().split()))
    A = sorted(a)
    count = 0
    ans = 0
    for i in A:
        if count < x:
            count += i
            ans += 1
    if count > x:
        ans -= 1
    if sum(A) < x:
        ans -= 1
    print(ans)
resolve()

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n,x = map(int,readline().split())
lst1 = list(map(int,readline().split()))

lst1.sort()

i = 0
ans = 0
while i < n:
    if lst1[i] > x:
        break
    x -= lst1[i]
    ans += 1
    i += 1

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

Solution (Python):
from typing import SupportsComplex


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

result = []
for v in a:
    if x >= v:
        result.append(v)
        x -= v
    else:
        break

if len(result) == 0:
    print(0)
    exit()

if (x > 0) and (len(result) == len(a)):
    result[-1] += x

if result[-1] != a[len(result)-1]:
    ans = len(result)-1
else:
    ans = len(result)

print(ans)

Solution (Python):
n,k = map(int,input().split())
L = list(map(int,input().split()))
L.sort()

sum1 = 0
cnt = 0
if k < L[0]:
    print(0)
    exit()
for i in range(n):
    sum1 +=L[i]
    if sum1 <=k:
        cnt +=1
        if i == n-1 and sum1 != k:
            cnt -=1
    else:
        break
print(cnt)

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

count = 0

a.sort()

for idx, v in enumerate(a):
    if v <= x:
        x -= v
        if idx == N - 1:
            if x == 0:
                count += 1
        else:
            count +=1

print(count)

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

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

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

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

if a[-1] == x:
  print(ans+1)
else:
  print(ans)

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

aN.sort()
ans = 0
for n in range(N):
  if x >= aN[n]:
    ans += 1
    x -= aN[n]
  else:
    print(ans)
    sys.exit()
print(N if x == 0 else N-1)

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

Solution (Python):
N,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
total=0
j=0
ssum=sum(a)

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

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

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

ans = 1

s.sort()

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

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, x = map(int, readline().split())
    a = list(map(int, readline().split()))
    a.sort()

    rem = x
    ans = 0

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

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

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
for i in range(n):
  if a[i]>x:
    print(i)
    exit()
  x-=a[i]
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()

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

print(count)

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

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

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

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

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

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

    else:
        i -= 1
        break
print(i+1)

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

res=0
i=0
a.sort()

while 0<x and i < n:
    if a[i] <= x:
        res+=1
    x-=a[i]
    i+=1
if 0 < x:
    print(res-1)
else:
    print(res)

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

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

print(n-1)

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

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

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

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

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

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

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

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

al.sort()

cnt = 0

for a in al[:N-1]:
  if x >= a:
    x -= a
    cnt += 1
  else:
    break
if al[-1] == x:
  cnt += 1

print(cnt)

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

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

Solution (Python):
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

N, x = ri_()
a = sorted(ri_())
ans = 0
for i in range(N):
    if i < N - 1:
        x -= a[i]
        if x >= 0:
            ans += 1
        else:
            break
    else:
        if x == a[i]:
            ans += 1
print(ans)

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

print(count)

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

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

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

i = 0
while True:
    x = x - a[i]
    if x >= 0 and i+1 != len(a):
        i += 1
    elif x == 0 and i+1 == len(a):
        i += 1
        break
    else:
        break

print(i)

Solution (Python):
N, x = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
sum = 0
ans = 0
for i,a in enumerate(A):
    sum += a

    if sum == x:
        ans = i + 1
        break
    elif sum > x:
        break
    elif i + 1 == N and sum < x:
        ans = i
        break
    ans = i + 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-1)
  exit()
cnt = 0
su = 0
for i in range(N):
  if su + a[i] <= x:
    su += a[i]
    cnt += 1
  else:
    break
print(cnt)

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

ans=0
rest=x
target=sorted(a)
if sum(target)<x:
    print(n-1)
elif sum(target)==x:
    print(n)
else:
    for i in range(n):
        rest-=target[i]
        if rest<0:
            ans=i
            break
        if rest==0:
            ans=i+1
            break
    print(ans)