Problem:
 Score : 200 points    Problem Statement There are N children, numbered 1, 2, ..., N .  Snuke has decided to distribute x sweets among them.
He needs to give out all the x sweets, but some of the children may get zero sweets.  For each i ( 1 \leq i \leq N ), Child i will be happy if he/she gets exactly a_i sweets.
Snuke is trying to maximize the number of happy children by optimally distributing the sweets.
Find the maximum possible number of happy children.      Constraints  All values in input are integers.  2 \leq N \leq 100  1 \leq x \leq 10^9  1 \leq a_i \leq 10^9         Input Input is given from Standard Input in the following format:  N  x  a_1  a_2  ...  a_N       Output Print the maximum possible number of happy children.        Sample Input 1 3 70
20 30 10      Sample Output 1 2  One optimal way to distribute sweets is (20, 30, 20) .       Sample Input 2 3 10
20 30 10      Sample Output 2 1  The optimal way to distribute sweets is (0, 0, 10) .       Sample Input 3 4 1111
1 10 100 1000      Sample Output 3 4  The optimal way to distribute sweets is (1, 10, 100, 1000) .       Sample Input 4 2 10
20 20      Sample Output 4 0  No children will be happy, no matter how the sweets are distributed.

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

Solution (Python):
import sys
N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
i = 0
while i < N:
    if A[i] <= x:
        x -= A[i]
        i += 1
    else:
        print(i)
        sys.exit()
if x > 0:
    print(i - 1)
else:
    print(i)

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

Solution (Python):
def resolve():
    '''
    code here
    '''
    N, x = [int(item) for item in input().split()]
    As = [int(item) for item in input().split()]
    As.sort()

    cnt = 0
    while x > 0 and cnt < N:
        x -= As[cnt]
        if cnt == N-1:
            if x == 0:
                cnt += 1
        else:
            if x >= 0:
                cnt += 1
    
    print(cnt)


if __name__ == "__main__":
    resolve()

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

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

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

Solution (Python):

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

ans = 0

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

print(ans)

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

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


resolve()

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

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

else:
    c = 0
    for ai in A:
        x -= ai
        if x <= 0:
            break
        c += 1

    if c == N:
        print(N - 1)
    else:
        print(c + 1 if x == 0 else c)

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

if sum(A) < x:
    print(N-1)
    exit()

A = [1] + A
ans = 0
while A[-1] <= x:
    x -= A[-1]
    A.pop()
    ans += 1
print(ans)

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

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

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

a_list=[int(i) for i in input().split()]

a_list.sort()

if x>sum(a_list):
    print(n-1)


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

Solution (Python):
from itertools import accumulate

n, x, *aa = map(int, open(0).read().split())

aa.sort()

aa = list(accumulate(aa))

ans = len([a for a in aa if a<=x])
if ans >= 1 and aa[-1]<x:
    ans -=1

print(ans)

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

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

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

ans = 0
a.sort()
a_sum = [sum(a[:i+1]) for i in range(len(a))]

for i, item in enumerate(a_sum):
    if x < item:
        ans = i
        break
    elif x == item:
        ans = i+1
        break
    elif x > item and i == len(a_sum)-1:
        ans = i
        break

print(ans)

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

if x > sum(a):
  print(n - 1)
else:
  c = 0
  while x >= a[-1]:
    x -= a.pop()
    c += 1
    if c == n:
      break
  print(c)

Solution (Python):
n, x = [int(w) for w in input().split()]
a_li = [int(w) for w in input().split()]
a_li.sort()
 
ans = 0
for a in a_li:
    x -= a
    if x >= 0:
        ans += 1
    else:
        break
 
if x == 0:
    pass
else:
    if x > 0:
        ans = max(ans - 1, 0)
 
print(ans)

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

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

if x == 0:
    pass
else:
    if x > 0:
        ans = max(ans - 1, 0)

print(ans)

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

cnt = 0

if x == sum(a_lst):
    print(len(a_lst))
elif x > sum(a_lst):
    print(len(a_lst)-1)
else:
    for i in a_lst:
        x -= i
        if x < 0:
            break
        cnt += 1
    print(cnt)

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

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

if x==A[-1]:
    K+=1

print(K)

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

Solution (Python):




import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy











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
    elif A[i] <= X:
        ans += 1
        X = X - A[i]
    else:
        break

print(ans)

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

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

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

ans=0
i=0
while X and i<N-1:
    X-=A[i]
    if X>=0:
        ans+=1
    else:
        break
    i+=1

if i==N-1 and A[i]==X:
    ans+=1

print(ans)

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

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

a.sort()
ans = [0]*n
if (sum(a) == x):
    print(n)
else:
    for i in range(n):
        if (x >= a[i]):
            ans[i] = 1
            x -= a[i]
        else:
            print(sum(ans))
            exit()
    if (0 in ans):
        print(sum(ans))
    else:
        print(sum(ans)-1)

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

if x == sum(A):
    print(N)
else:
    A.sort()
    ans = 0
    for a in A[:-1]:
        if x >= a:
            ans += 1
            x -= a
        else:
            break
    print(ans)

Solution (Python):









import sys
input = sys.stdin.readline

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

list_sum = [0]
for i in range(N):
    list_sum.append(list_sum[i] + list_N[i])

ans = 0
for i in range(N + 1):
    if list_sum[i] <= x and i < N:
        ans = i
    elif i == N and list_sum[i] == x:
        ans = i


print(ans)

Solution (Python):
N,X = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
k1 = k2 = 0
for i in range (N):
  if sum(A[:i+1]) > X:
    k1 = i
    k2 = 1
    break
  elif sum(A) == X:
    k1 = N
    k2 = 1
    break
if k2 == 0:
  k1 = N - 1
print(k1)

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

Solution (Python):
N,X = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
k1 = k2 = 0
for i in range (N):
  if sum(A[:i+1]) > X:
    k1 = i
    k2 = 1
    break
  elif sum(A) == X:
    k1 = N
    k2 = 1
    break
if k2 == 0:
  k1 = N - 1
print(k1)

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

s = 0
cnt = 0
for i in a:
    s += i
    if s > x:
        break
    cnt += 1

if s < x:
    cnt -= 1    
print(cnt)

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

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

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

a.sort()

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

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

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

count = 0
for child in children:
    if x >= child:
        x -= child
        count += 1
    else:
        break
else:
    if x != 0:
        count -= 1

print(count)

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

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

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

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


a.sort(reverse=False)
for i in range(N):
    if x >= a[i]:
        count += 1
        x -= a[i]
    else:
        break

if (x!=0)and(count == N):
    count -= 1
print(count)

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

a.sort()

Q=0
for i in range(N):
    if x>=a[i] and i!=N-1:
        Q+=1
        x=x-a[i]
    elif i==N-1 and x==a[i]:
        Q+=1
print(Q)

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

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7


N, x = MAP()
a = LIST()

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7


N, x = MAP()
a = LIST()

a.sort()
A = list(accumulate(a))

n = bisect(A, x)
if n == N and A[-1] < x:
	print(n-1)
else:
	print(n)

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

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

Solution (Python):
import sys
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]:
    x -= a[i]
    count += 1
    if i == n-1 and x > 0:
      print(count-1)
      sys.exit()
    elif i == n-1 and x == 0:
      print(count)
      sys.exit()
  else:
    print(count)
    sys.exit()

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

s.sort()
cnt = 0

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

if x > 0:
    cnt -= 1

print(cnt)

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

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

print(ans)

Solution (Python):




from __future__ import division, print_function 

import sys
import os
from collections import Counter, deque, defaultdict
import itertools
import math
import io


"""Uncomment modules according to your need"""













if sys.version_info[0] < 3:
    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip



"""value of mod"""
MOD = 998244353
mod = 10**9 + 7

"""Uncomment next 4 lines if doing huge recursion"""




def prepare_factorial(mod=mod):
    """ returns two lists, factorial and inverse factorial modulo argument by default 10**9 +7 """
    
    fact = [1]
    for i in range(1, 200005):
        fact.append((fact[-1] * i) % mod)

    ifact = [0] * 200005
    ifact[200004] = pow(fact[200004], mod - 2, mod)
    for i in range(200004, 0, -1):
        ifact[i - 1] = (i * ifact[i]) % mod

    return fact, ifact

def modinv(n, p):
    """ returns N inverse modulo p """
    return pow(n, p - 2, p)

def ncr(n, r,  fact, ifact):
    """ takes 4 arguments: n , r and factorial and inverse factorial lists"""
    t = (fact[n] * (ifact[r]*ifact[n-r]) % MOD)% MOD
    return t


def get_n(Sum):    
    """this function returns the maximum n for which Summation(n) <= Sum"""
    ans = (-1 + sqrt(1 + 8*Sum))//2
    return ans

def sieve(n):
    """ returns a list of prime numbers till n """
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r



def divs(n, start=1):
    """ returns a list of all divisors till n """
    divisors = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return divisors



def divn(n, primes):
    """ returns the number of divisors, two arguments n and the sieve till n """
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t



def lrfind(d, x, default=-1):
    """ Takes 2 arguments an iterable and an element. returns a tuple (firstoccurence,lastoccurence) -1 if not found """
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return default, default
    else:
        return left, right

def gcd(x, y): 
    """ returns greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x

def check_sorted(a):
    ''' returns True/False '''
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
            return False
    return True
def ceil(n, k=1): return n // k + (n % k != 0) 
def input(): return sys.stdin.readline().strip()
def ii(): return int(input()) 
def mi(): return map(int, input().split()) 
def li(): return list(map(int, input().split())) 
def lw(): return input().split() 
def lcm(a, b): return abs(a * b) // gcd(a, b) 
def prr(a, sep=' ', end='\n'): print(sep.join(map(str, a)), end=end) 
def dd(): return defaultdict(int) 
def ddl(): return defaultdict(list) 
def write(s): return sys.stdout.write(s)













def main():
    
    n,x=mi()
    a=li()
    a.sort()
    i=0
    count=0
    while x>0 and i<n-1:
        c=10**9+1
        if a[i]<=x:
            c=min(x,a[i])
            a[i]-=c
            if a[i]==0:
                count+=1
        x=x-c
        i+=1
    if x==a[-1]:
        count+=1
    print(count)
    

















    
""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192

class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill();
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):

    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode('ascii'))
            self.read = lambda: self.buffer.read().decode('ascii')
            self.readline = lambda: self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')



""" main function"""

if __name__ == '__main__':
    main()

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

lis.sort()
for i in lis:
    x -= i
    if x >= 0:
        c += 1
    else:
        break

if x > 0:
    c -= 1

print(c)

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

nums = sorted(list(map(int, input().split())))

count = 0
for i, num in enumerate(nums):
    if (i < n-1 and num <= x) or (i == n-1 and num == x):
        count += 1
        x -= num        
    else:
        break

print(count)

Solution (Python):

n, x = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
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):
def main():
    from builtins import int, map, list, print
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    N, x = input_number_list()
    A = input_number_list()
    A.sort()
    ans = 0
    tmp_sum = 0
    for a in A:
        tmp_sum += a
        if tmp_sum > x:
            break
        else:
            ans += 1
    if ans == N and tmp_sum != x:
        ans -= 1
    print(ans)


if __name__ == '__main__':
    main()

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

ans = 0

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

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

tmp = 0
ans = 0

for a in A:
    tmp+=a
    if tmp<=X:
        ans+=1
if ans==N and tmp<X:
    ans-=1
print(ans)

Solution (Python):


import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, x, *A = map(int, read().split())
A = sorted(A)
cnt = 0

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

if x > 0:
    ans -= 1
else:
    pass

print(ans)

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

A = sorted(A)

i = 0
while i < N:
    if A[i] <= x:
        x -= A[i]
        i += 1
    else:
        break

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

print(i)

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

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

Solution (Python):
N, X = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
res = 0
for a in A:
    if a > X:
        break
    res += 1
    X -= a
else:
    if X > 0:
        res -= 1
print(max(res, 0))

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

Solution (Python):
n,x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
s = [0] * (n+1)
for i in range(n):
    s[i+1] = s[i] + a[i]

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

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

Solution (Python):
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

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

    if sum(A) == X:
        print(N)
    else:
        ans = 0
        for a in A[:-1]:
            if a <= X:
                ans += 1
                X -= a
            else:
                break
        print(ans)


if __name__ == '__main__':
    main()