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 IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))

def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]

def to_bin(x: int) -> str: return format(x, 'b') 
def to_oct(x: int) -> str: return format(x, 'o') 
def to_hex(x: int) -> str: return format(x, 'x') 
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]

from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left



def main():
    n, x = MII()
    aa = MII()
    aa.sort()
    cnt = 0
    if x > sum(aa):
        cnt -= 1
    for a in aa:
        if x >= a:
            x -= a
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

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

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

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


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

Solution (Python):



import sys





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


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


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


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


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


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

Solution (Python):

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

a.sort()
distributed = 0
beGlads = 0

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

print(beGlads if sum(a) >= x else beGlads - 1)

Solution (Python):


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

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

Solution (Python):

import sys
input=sys.stdin.readline
from bisect import bisect_right
import itertools

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

A.sort()
Acum = list(itertools.accumulate(A))
answer = bisect_right(Acum,X)
if answer == N:
    if Acum[-1] < X:
        answer -= 1
print(answer)

Solution (Python):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

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

ans = 0
total = 0

a_list.sort()

for i, a in enumerate(a_list):
    total += a

    if x < total:
        break
            
    elif i == len(a_list) - 1 and x > total:
        None
        
    else:
        ans += 1
    
print(ans)

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

else:
    num=N-1
print(num)

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

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

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

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

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

if x > 0 and cnt > 0:
    cnt -= 1

print(cnt)

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

if X < la[0]:
    print(0)
elif X > sum(la):
    print(N-1)
elif X == sum(la):
    print(N)
else:
    j = 0
    while X > 0:
        X = X - la[j]
        j += 1
    if X < 0:
        print(j-1)
    else:
        print(j)

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

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

for i, a in enumerate(A):
    if a > x:
        print(answer)
        exit()
    if i == N-1:
        if a != x:
            print(answer)
        else:
            answer += 1
            print(answer)
    else:
        x -= a
        answer += 1

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

Solution (Python):
def resolve():
    def main():
        import sys
        n,x=map(int, input().split())
        l=list(map(int, input().split()))
        l.sort()
        cnt=0
        for i in range(n):
            if l[i]<=x:
                x-=l[i]
                cnt+=1
            else:
                return i
        if cnt==n and x>0:
            cnt-=1
        return cnt
    print(main())
resolve()

Solution (Python):
def resolve():
    import sys
    n,x=map(int, input().split())
    l=list(map(int, input().split()))
    l.sort()
    cnt=0
    for i in range(n):
        if l[i]<=x:
            x-=l[i]
            cnt+=1
        else:
            print(i)
            sys.exit()
    if cnt==n and x>0:
        cnt-=1
    print(cnt)
resolve()

Solution (Python):
import numpy as np
import sys

input = sys.stdin.readline

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:
        print(i)
        exit()

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

print(ans)

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

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

r = 0
for a in A:
    if x - a < 0:
        break
    else:
        x -= a
        r += 1
if x > 0 and r == N:
    r -= 1

print(r)

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

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

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

arr.sort()
ans = 0

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

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

print(ans)

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

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

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

A = sorted(a)

for i in range(N):
    maxcandy += A[i]

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

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

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

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    res = 0
    for i in range(n):
        if i == n - 1 and A[i] < x:
            continue

        if A[i] <= x:
            x -= A[i]
            res += 1

    print(res)


if __name__ == '__main__':
    resolve()

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

Solution (Python):
import sys


def readlines(n):
    for _ in range(n):
        yield map(int, input().split())


def main():
    N, x = map(int, input().split())
    A = sorted(map(int, input().split()))

    for a in A:
        if a > x:
            yield 0
            return
        elif x > 0:
            x -= a
            yield 1
        else:
            yield 0
            return

    if x > 0:
        yield -1

print(sum(main()))

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

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

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

a.sort()
ans = 0
for ai in a:
    if x - ai < 0:
        x -= ai
        break
    x -= ai
    ans += 1

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

Solution (Python):
N,x = map(int, input().split())
A = sorted(list(map(int, input().split())))
ans = 0
for i in range(1, N+1):
    x -= A.pop(0)
    if x == 0:
        ans = i
        break
    elif x < 0:
        ans = i-1
        break
else:
    ans = N-1

print(ans)

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

a.sort()
c = 0
ans = 0

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

if c == 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 a in A:
    x = x - a
    if x < 0:
        break
    ans += 1
if x > 0 and ans > 0:
    ans -= 1
print(ans)

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

Solution (Python):
from sys import stdin
import math

[N, x] = list(map(int, stdin.readline().rstrip().split()))
a = list(map(int, stdin.readline().rstrip().split()))

a_sorted = sorted(a)


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

if x > 0:
    count -= 1

print(count)

Solution (Python):
_, x, *a = map(int, open(0).read().split())
c = 0
for i in sorted(a):
  x -= i
  if x<0:
    break
  c += 1
print(c - (x>0))

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

for i in range(1, len(A)+1):
    
    
    
    if x < sum(A[:i]):
        
        print(i-1)
        break
    elif x == sum(A[:i]):
        
        print(i)
        break
    else:
        if i == len(A):
            print(i-1)

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

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

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

Solution (Python):

n, x = map(int, input().split())
nums = [int(i) for i in input().split()]
nums.sort()


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

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

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


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


if __name__ == '__main__':
    main()

Solution (Python):
N,X = map(int,input().split(' '))
num_list = list(map(int,input().split(' ')))
num_list_s = sorted(num_list)
total = 0
index = 0
for i in range(N):
    total += num_list_s[i]
    if total > X:
        break
    else:
        index += 1
if sum(num_list) < X:
    print(index-1)
else:
    print(index)

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

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

i = 0
while i < N and x > 0:
    x -= sorted_A[i]
    i += 1

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

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

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

    a.sort()

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

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

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

a = sorted(a)
ans = 0

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

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

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] or (i==n-1 and x!=a[i]):
        break
    else:
        x-=a[i]
        cnt+=1


print(cnt)

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

Solution (Python):
N,X=map(int,input().split())
L=list(map(int,input().split()))
L=sorted(L)
count=0
for i in range(N):
	if i==(N-1):
		if X!=L[i]:
			count=count
		else:
			count+=1
	elif L[i]<=X:
		X-=L[i]
		count+=1
	
print(count)

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


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

a.sort()
candies = 0
ans = 0

for ai in a:
	if candies < x:
		candies += ai
		ans += 1
	else:
		break

if candies != x:
	ans -= 1

print(ans)

Solution (Python):
N, X = map(int, input().split())
A = sorted(list(map(int, input().split())))
l = [0]*N
for i in range(N):
  if X >= A[i]:
    if i == N-1:
      l[i] = X
      X -= X
    else:
      l[i] = A[i]
      X -= A[i]
  else:
    l[i] = X
    X -= X
ans = [A[i]-l[i] for i in range(N)].count(0)
print(ans)

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

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

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

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

if x == 0 or ans == 0 or ans < N:
  print(ans)
else:
  print(ans-1)

Solution (Python):
import numpy as np
n,x = map(int,input().split())
li = list(map(int,input().split()))
li.sort()
res = np.cumsum(li)
cnt=0
if res[-1] == x:
    cnt = len(res)
elif res[-1] > x:
    for i in res:
        if i <= x:
            cnt += 1
        else:
            break
else:
    cnt = len(res) -1
print(cnt)

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

a.sort()

ans = 0
i = 0

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

if 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()
n = 0

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

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

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

a = sorted(a)

re = x
i = 0
ans = 0

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

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

print(ans)

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


if __name__ == '__main__':
    main()

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

if x == sum(sweets):
    print(N)
else:
    
    sweets.remove(max(sweets))
    ans = N - 1
    while True:
        if x >= sum(sweets):
            print(ans)
            break

        sweets.remove(max(sweets))
        ans -= 1

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

ans=0
if sum(a_inputs)<x:
    ans=n-1
else:
    while a_inputs:
        a = a_inputs.pop(0)
        if a<=x:
            x-=a
            ans+=1
        else:
            break
print(ans)

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

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

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

i = 0
while len(a) > 0:
    if min(a) > x:
        break
    else:
        x -= min(a)
        a.remove(min(a))
        i += 1
if len(a) == 0:
    if x > 0:
        i -= 1
print(i)

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

N, x = getInput()
a = sorted(getInput())
cnt=0
for i in a:
    x -= i
    if x<0: break
    cnt+=1

print(cnt-(x>0))

Solution (Python):
n, x = map(int, input().split())
a = [int(x) for x in 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
  else:
    break
print(ans)

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

Slist = sorted(a)
cnt = 0
Sum = 0

if x > sum(Slist):
  print(n-1)
  exit()
  
for i in range(n):
  Sum += Slist[i]
  if x>=Sum:
    cnt +=1
  else:
    break
print(cnt)

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

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

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

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

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

ans = 0
for i in l:
    if i <= x:
        x -= i
        ans += 1
if ans == n and x > 0:
    print(ans-1)
else:
    print(ans)

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

a.sort()

s = 0
counter = 0

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

print(counter)

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

a.sort()

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

Solution (Python):
N, x = map(int, input().split())
A = [int(x) for x in input().split()]
A = sorted(A)
cnt=0

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

if cnt==N and x > 0:
    cnt -= 1
print(cnt)

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

Solution (Python):

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

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

print(i)

Solution (Python):












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


arrA.sort()
ans = 0
flg = True
for i in range(N):
    if arrA[i]<=x:
        x -= arrA[i]
        ans += 1
    else:
        flg = False


if flg and x>0:
    print(ans-1)
elif flg and x == 0:
    print(ans)
elif not flg and x==0:
    print(ans)
else:
    print(ans)

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

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

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

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

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

a.sort()

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

if x > 0:
    ans -= 1

print(ans)

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

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

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

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

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

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

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

a.sort()
count = 0

for i in range(len(a)):
    tmp = a[i]

    if x >= tmp and i != len(a) - 1:
        count += 1
        x -= tmp
    else:
        if tmp == x:
            count += 1
        break

print(count)

Solution (Python):



import sys
input = sys.stdin.readline

def main():
    N, X = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    ret = 0
    cnt = 0
    if sum(A)<X:
        print(N-1)
    elif sum(A)==X:
        print(N)
    else:
        for i in range(N):
            X-=A[i]
            if X<0:
                break
        print(i)

if __name__ == '__main__':
    main()

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 -= a[i]
    else:
        break
if count == n:
    if x != 0:
        count -= 1
print(count)

Solution (Python):
from heapq import heapify, heappop, heappush









import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N, x = map(int, input().split())
    A = list(map(int, input().split()))
    cnt = 0
    heapify(A)
    while True:
        if cnt < N:
            p = heappop(A)
            x -= p
            if x>=0:
                cnt += 1
            else:
                break
        else:
            break
    if cnt==N and x!=0:
        cnt-=1
    print(cnt)


resolve()

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

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

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

Solution (Python):

n,x = map(int,input().split())
a = list(map(int,input().split()))
if sum(a) == x:
    print(n)
    exit()

a.sort()
cnt = 0
for i in a:
    if x>=i:
        cnt += 1
        x -= i
if cnt == n:
    cnt-=1
print(cnt)