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
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





N,x = IL()
A = IL()
A.sort()

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

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

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, X = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]

    A.sort()
    ans = 0
    for a in A:
        if X >= a:
            ans += 1
            X -= a

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

    print(ans)


if __name__ == '__main__':
    main()

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

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

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

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

print(ans)

Solution (Python):
def resolve():
    N, x = list(map(int, input().split()))
    a = list(map(int, input().split()))
    dist = []

    ans = 0
    a.sort()

    for i, con in enumerate(a):
        if i == len(a)-1:
            dist.append(x - sum(dist))

        if sum(dist) + con <= x:
            dist.append(con)
        else:
            dist.append(0)

    for i in range(len(a)):
        if a[i] == dist[i]:
            ans += 1
    print(ans)
    return
resolve()

Solution (Python):
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.buffer.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

def heapsort(iterable):
    h = []
    for value in iterable:
        heapq.heappush(h, value)
    return [heapq.heappop(h) for i in range(len(h))]

n, k = rm()
a = rl()
a = heapsort(a)
cnt = 0
for i in a:
    k -= i
    if k < 0:
        break
    else:
        cnt += 1
else:
    if k != 0:
        cnt -= 1
print(cnt)

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

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

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

print(cnt)

Solution (Python):
N,x = map(int,input().split())
a = sorted(list(map(int,input().split())))
s = [sum(a[:i+1]) for i in range(N)]

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

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

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

li.sort()
ans = 0

for i in li:
    x -= i
    if x >= 0:
        ans += 1

print(ans)

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

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

res=0
for a in vA:
	if a<=X:
		res += 1
		X -= a
	else:
		break
else:
	if X:
		res = max(0, res-1)

print(res)

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

a.sort()

cnt = 0
for i, child in enumerate(a):
    if x == 0:
        break
    if child == x:
        cnt += 1
        break
    if child < x:
        
        if i == len(a) - 1:
            break
        x -= child
        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 a[i] == x:
    ans+=1
    break
  elif a[i] > x:
    break
  else:
    if i!=(n-1):
      ans+=1
      x-=a[i]
print(ans)

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

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

kids.sort()
i=0
while i<n and x>=kids[i]:
  x-=kids[i]
  i+=1

if x!=0 and i==n:
  i-=1
if i<0:
  i=0
  
print(i)

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

cnt = 0
for e in A:
    if e <= x:
        x = x - e
        cnt += 1
if cnt == n and x > 0:
    print(cnt-1)
else:
    print(cnt)

Solution (Python):
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 18

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

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

l = sorted(a)
flag = False
for i in range(n):
    x -= l[i]
    if x < 0:
        flag = True
        break
if flag:
    print(i)
elif x == 0:
    print(n)
elif x > 0:
    print(n - 1)

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

Solution (Python):






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





a_sum = sum(a)
if a_sum == x:
    print(N)
elif a_sum < x:
    print(N-1)
else:
    for i in range(N):
        if x < sum(sorted(a, reverse=False)[:i+1]):
            print(i)
            break

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)
      exit()
    elif x==0:
      print(-~i)
      exit()
print(n-1)

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

a_sort = sorted(a)
ans = 0

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

print(ans)

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

Solution (Python):

import sys


from bisect import bisect_right
import itertools


def solve(N: int, x: int, a: "List[int]"):
    a.sort()
    acum = list(itertools.accumulate(a))
    ans = bisect_right(acum, x)
    if ans == N and acum[-1] < x:
        ans -= 1
    print(ans)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  
    x = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(N)]  
    solve(N, x, a)


if __name__ == "__main__":
    main()

Solution (Python):
import sys

input = sys.stdin.readline


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

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

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

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

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

Solution (Python):
N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans, cur = 0, 0
if(sum(a) <= x):
    if(sum(a) != x): N -= 1
    print(N)
    exit(0)

for i in range(N):
    cur += a[i]
    if(cur > x): break
    ans += 1
print(ans)

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

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

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

A = sorted(A)

tmp = 0
count = 0
for i, a in enumerate(A):
    if tmp + a > x:
        break
    if (i == len(A) -1) and tmp + a < x:
        break
    tmp += a
    count += 1

print(count)

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

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

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

Solution (Python):

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

A.sort()
ans = []
for i in A:
	x -= i
	
	if x >= 0:
		ans.append(i)
	else:
		break
	
if x > 0:
	print(len(ans)-1)
else:
	print(len(ans))

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

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

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

a.sort()

current = x
result = 0

for i in range(N):
    if  current >= a[i]:
        current -= a[i]
        result += 1

if result == N and current > 0:
    result -= 1

print(result)

Solution (Python):
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
result = 0
sorted_a = sorted(a)
remain = x
for a_i in sorted_a:
    if remain >= a_i:
        result += 1
        remain -= a_i
    else:
        break


if result == N and remain != 0:
    result -= 1
print(result)

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

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

for i in a:
  if x - i >= 0:
    x -= i
    count += 1
if x > 0 and count != 0  and p > sum(a):
  count -= 1
print(count)

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

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

sum = 0
count = 0
for i in a[:-1]:
  sum+=i
  if sum>k:
    break
  count+=1
if a[-1]==k-sum:
  count+=1
print(count)

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

print(ans)

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

Solution (Python):

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

s.sort()
s.reverse
ans=0
if s[0]>x:
    print(ans)
else :
    for i in s:
        x=x-i
        if x>=0:
            ans+=1
        else :
            break
    if x>0:
        ans-=1
    print(ans)

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

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

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

for i, v in enumerate(a):
    x -= v
    if x < 0:
        ans = i
        break
    if x == 0:
        ans = i + 1
        break
    if i == N - 1: 
        ans = i + 1
if x > 0:
    ans -= 1
print(ans)

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

for i, v in enumerate(a):
    x -= v
    if x < 0:
        ans = i
        break
    if x == 0:
        ans = i + 1
        break
    if i == N - 1: 
        ans = i + 1
if x > 0:
    ans -= 1
print(ans)

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

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

a = sorted(a)

count = 0

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

if a[-1] == x:
    count += 1

print(count)

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

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

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

    ans = 0
    num_list.sort()

    for num in num_list:
        if x - num >= 0:
            x -= num
            ans += 1
        else:
            break

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

    print(ans)


if __name__ == '__main__':
    main()

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

if total<x:
  print(N-1)

elif total==x:
  print(N)

else:
  ans=0
  d=[0]*N
  for i in range(N):
    if x>=a[i]:
      x-=a[i]
      d[i]=1
  ans=d.count(1)
  print(ans)

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

Solution (Python):
from bisect import bisect_left
from itertools import accumulate


N, x = map(int, input().split())
a = list(accumulate(sorted(map(int, input().split()))))
if x in a:
    print(bisect_left(a, x) + 1)
else:
    pos = bisect_left(a, x)
    print(N - 1) if pos == N else print(pos)

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

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

Solution (Python):
from itertools import accumulate
import bisect
N, x = map(int, input().split())
a = sorted(list(map(int, input().split())))
c = list(accumulate(a))
ans = bisect.bisect_right(c, x)
if not ans:
  print(ans)
else:
  print(ans if c[N - 1] >= x else ans - 1)

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

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

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

    if ans == n:
        ans -= 1


    print(ans)

Solution (Python):
n , x = map(int, input().split())
a = list(map(int,input().split()))
a.sort()
ans = 0
while x>0 and a:
    c = a.pop(0)
    if x>=c:
        ans +=1
    x-=c
if x>0:
    ans-=1
print(ans)

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

if X == min(a):
  print(1)
elif X == sum(a):
  print(len(a))
else:
  while X > 0 and N > 0:
    X -= min(a)
    N -= 1
    a.remove(min(a))
    ans += 1
  print(ans - 1)

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

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 x < a[i]:
            print(i)
            break
        x -= a[i]

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

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

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


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

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


def read():
    N, x = map(int, input().strip().split())
    A = map(int, input().strip().split())
    return N, x, A


def solve(N, x, A):
    count = 0
    for a in sorted(A):
        x -= a
        if x < 0:
            break
        count += 1
    if x > 0:
        count -= 1
    return max(count, 0)


if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Solution (Python):
from itertools import accumulate
from operator import add

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

if sum(A) == x:
    print(N)
else:
    t = len(list(filter(lambda y: y <= x, accumulate(A, func=add))))
    if t == N:
        print(N - 1)
    else:
        print(t)

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

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

Solution (Python):
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007
INF = 122337203685477580

def solve():
    N,x = map(int, input().split())
    vec =list(map(int, input().split())) 
    vec.sort()
    SUM = 0
    i = 0
    for p in range(N):
        SUM += vec[p]


        
        if(SUM > x):
            break
        
        i += 1

    if(x > sum(vec)):
        i -= 1
    print(i)
        
if __name__ == '__main__':
    solve()

Solution (Python):
import math



def inp():
    return(int(input()))



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



def instr():
    s = input()
    return(list(s[:len(s)]))



def invr():
    return(map(int, input().split()))


N, x = invr()

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

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

Solution (Python):
N,X = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a)
m = sum(a)
count = 0
S=0
if m == X:
    print(N)
elif m < X:
    print(N-1)
elif a[0] > X:
    print(0)
else: 
    for i in a:
        if S <= X:
            S = S + i
            count = count + 1
    else:
        print(count-1)

Solution (Python):
def last_alert(list_):
    iter_ = iter(list_)
    n = next(iter_)
    for i in iter_:
        yield n, False
        n = i
    yield n, True


N, X = map(int, input().split())
ans = 0
for i, is_last in last_alert(sorted(map(int, input().split()))):
    if is_last and X != i:
        break
    elif X < i:
        break
    X -= i
    ans += 1
print(ans)

Solution (Python):
import math
from collections import deque
from collections import defaultdict


def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): 
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): 
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} 
def bitArr(n):
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): 
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq

n,x = readInts()
a = readInts()
a.sort()
ans = []

if a[0]>x:
	print(0)
	exit()
elif sum(a)<x:
	print(len(a)-1)
	exit()

for i in range(1,len(a)+1):
	if sum(a[:i])<=x:
		ans = a[:i]
	else:
		break


print(len(ans))

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