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=input().split()
X=int(x)
n=int(N)
y=0
A = [int(i) for i in input().split()]
A.sort()
for z in range(n):
  y+=A[z]
  if y>=X:
    if y==X:
      print(z+1)
    else:
      print(z)
    break
else:
  print(n-1)

Solution (Python):


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

a = sorted(a)
if x < a[0]:
    print(0)
    exit()

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

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

ans = cnt 
print(ans)

Solution (Python):


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

a = sorted(a)
if x < a[0]:
    print(0)
    exit()

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

if al: 
    if x > 0:
        ans = cnt-1
    else:
        ans = cnt 
else:
    ans = cnt 

print(ans)

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

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

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

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

a = sorted(a)

M = []
cn = 0

for i in range(N):
    x = x - a[i]


    
    if x >= 0 and i != N-1: 
        cn = cn + 1
    elif x < 0:
        print(cn)
        break
    elif i == N-1:
        if x == 0:
            cn = cn + 1
            print(cn)
            break
        else:
            print(cn)
            break

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

A.sort()

for i, a in enumerate(A):
  x -= a
  if x == 0:
    print(i+1)
    exit()
  elif x < 0:
    print(i)
    exit()
print(N-1)

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

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

if sum(A) < x:
    print(N-1)
else:
    A.sort()
    count = 0
    while(x > 0):
        x -= A[count]
        if x >= 0:
            count += 1
    print(count)

Solution (Python):

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

cnt = 0
a.sort()

while x > 0:
    if cnt >= N:
        if x > 0:
            cnt -= 1
            break
        else:
            break
    elif a[0] > x:
        break
    else:
        tmp = a.pop(0)
        x -= tmp
        cnt+=1


print(cnt)

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

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

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

arr.sort()
ans = 0

for i in arr:
    x -= i
    if x < 0:
        break
    else:
        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()))

count = 0

while(len(A)) != 1:
    x -= min(A)
    if x < 0:
        break
    A.remove(min(A))
    count += 1
    if len(A) == 1:
        if x - min(A) == 0:
            count += 1

print(count)

Solution (Python):








A,B= map(int,input().split())
f = list(map(int,input().split()))






okasi=B
f.sort()
ans=0
for i in range(A):
    if B>=f[i]:
        B=B-f[i]
        ans+=1
    else:
        if B==okasi:
            ans=0
        break
    if B>0 and i==A-1:
        ans-=1

    


print(ans)

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


print(i)

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

for i in range(n):
    acsum.append(acsum[i] + a[i])

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

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
    elif x == i:
        cnt += 1
        break
    else:
        break
else:
    cnt -= 1

print(cnt)

Solution (Python):


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

    ans = 0

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

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

    print(ans)

if __name__ == "__main__":
    main()

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

num_lists.sort()
cnt = 0
sum = 0
for i in range(len(num_lists)):
    sum += num_lists[i]
    if sum <= x:
        cnt = i+1
    else:
        x = 0
        cnt = i
        break
x -= sum

if 0 < x:
    cnt -= 1

print(cnt)

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

import itertools

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

B = list(itertools.accumulate(sorted(A))) 
C = list(itertools.accumulate(sorted(A, reverse=True))) 

if B[-1] == x:
    print(len(A))
elif B[-1] < x:
    x -= B[-1]
    print(N - (len(list(itertools.takewhile(lambda e: e <= x, C))) + 1))
elif x < B[-1]:
    print(len(list(itertools.takewhile(lambda e: e <= x, B))))

Solution (Python):
import itertools

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

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

cnt = 0

for i in range(len(a)):
    if x > a[i]:
        if i == len(a)-1:
            break
        cnt += 1
    elif x == a[i]:
        cnt += 1
        break
    else:
        break

print(cnt)

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


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

Solution (Python):
import itertools

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

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

cnt = 0

for i in range(len(a)):
    if x > a[i]:
        if i == len(a)-1:
            break
        cnt += 1
    elif x == a[i]:
        cnt += 1
        break
    else:
        break

print(cnt)

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

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

ans = 0

if X > sum(A):
    print(N-1)
else:
    for i in range(len(A)):
        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()

ans = 0

if X > sum(A):
    print(N-1)
else:
    for i in range(len(A)):
        if X >= A[i]:
            X -= A[i]
            ans += 1
        else:
            break
    print(ans)

Solution (Python):
import sys
import copy
a = [int(c) for c in input().split()]
N=a[0]
x=a[1]
a = [int(c) for c in input().split()]
a.sort()
for i in range(N):
    x-=a[i]
    if x<0:
        print(i)
        sys.exit(0)
    elif x==0:
        print(i+1)
        sys.exit(0)

print(N-1)

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

s = 0
num = 0
if x>sum(a):
  print(len(a)-1)
else:
  for i in range(len(a)):
      if x >= a[i]:
          x -= a[i]
          num += 1
      else:
          break

  print(num)

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

s = 0
num = 0
if x>sum(a):
  print(len(a)-1)
else:
  for i in range(len(a)):
      if x >= a[i]:
          x -= a[i]
          num += 1
      else:
          break

  print(num)

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

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

a.sort()
for i in range(n):
    if x >= a[i] and i < n - 1:
        x -= a[i]
        count += 1
    elif x == a[i] and i == n - 1:
        count += 1
print(count)

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

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

Solution (Python):

import sys
input=sys.stdin.readline

def main():
    children=[]
    n,x = map(int,input().split())
    children=list(map(int,input().split()))
    sorted_chiledren=sorted(children)
    counter=0
    last=x

    if sum(children) == x:
        print(n)
        exit()
    elif min(children) > x:
        print(0)
        exit()

    for idx,data in enumerate(sorted_chiledren):
        if data < last:
            last-=data
            counter+=1
            if idx+1==n:
                print(counter-1)
                exit()
        elif data == last:
            counter+=1
            print(counter)
            exit()
        else:
            print(counter)
            break

    
if __name__=="__main__":
    main()

Solution (Python):
n, x = map(int, input().split())
a_l = list(map(int, input().split()))
a_l = sorted(a_l)
ans = 0
for a in a_l:
    x = 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()))
sum_A = sum(A)

if sum_A == x:
    print(N)
elif sum_A < x:
    print(N-1)
else:
    A = sorted(A)
    cnt = 0
    for a in A:
        x -= a
        if x >= 0:
            cnt += 1
        else:
            print(cnt)
            break

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

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

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

Solution (Python):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from bisect import bisect
from itertools import accumulate

n,x=nii()
a=lnii()
a.sort()

b=list(accumulate(a))

if b[-1]<x:
  print(n-1)
else:
  inx=bisect(b,x)
  print(inx)

Solution (Python):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from bisect import bisect

n,x=nii()
a=lnii()
a.sort()

b=[0]
for i in range(1,n+1):
  b.append(a[i-1]+b[i-1])
b=b[1:]

if b[-1]<x:
  print(n-1)
else:
  inx=bisect(b,x)
  print(inx)

Solution (Python):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,x=nii()
a=lnii()
a.sort()

a_sum=0
for i in range(n):
  a_sum+=a[i]
  if a_sum>x:
    print(i)
    exit()

if x>sum(a):
  print(n-1)
else:
  print(n)

Solution (Python):
from sys import stdin

n, x = [int(x) for x in stdin.readline().split()]
a_lst = sorted([int(x) for x in stdin.readline().split()])
s = 0

for i, a in enumerate(a_lst):
  s += a
  if s > x:
    print(i)
    exit()
    
if s == x: print(i+1)
else: print(i)

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

for s in S:
  X -= s
  if X >= 0:
    cnt += 1
  else:
    break

if X > 0:
  cnt -= 1
    
print(cnt)

Solution (Python):

N,x = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
ans = 0
for a in A:
    x -= a
    if x<0 or (ans==N-1 and x!=0):
        break
    ans += 1
print(ans)

Solution (Python):

N,x = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
tmp = 0
ans = 0
for a in A:
    tmp += a
    if tmp<=x:
        ans += 1
    else:
        break
if ans==N and tmp!=x:
    ans -= 1
print(ans)

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

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

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

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

if sum(A) < x:
    cnt = -1
else:
    cnt = 0
    
for a in A:
    x -= a
    if x >= 0:
        cnt += 1
    if x <= 0:
        print(cnt)
        exit()
print(cnt)

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

a=sorted(a)

ans= 0

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

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

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

print(max(ans, 0))

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

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

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

print(ans)

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

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

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

arr.sort()
arr = list(accumulate(arr))


happy = bisect_right(arr, x)

if happy == n:
    if arr[-1] != x:
        happy -= 1

print(happy)

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

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

Solution (Python):
import sys
n,x = map(int, sys.stdin.readline().rstrip("\n").split())
a = [int(s) for s in sys.stdin.readline().rstrip("\n").split()]
a.sort()
ans = 0
for i in range(n):
    if i == n-1:
        if x - a[i] == 0:
            ans += 1
    else:
        if x-a[i] >= 0:
            x = x-a[i]
            ans += 1
print(ans)

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

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

Solution (Python):


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

a_sorted = sorted(a)

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

if reminder>0:
    num -= 1
    
print(num)

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


print(ans)

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

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

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

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

print(ans)

Solution (Python):
def main():
    v = list(map(int, input().split()))
    n = v[0]
    x = v[1]
    a = list(map(int, input().split()))

    
    count = 0
    a = sorted(a)

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

    print(count)


if __name__ == "__main__":
    main()

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

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

Solution (Python):
a,b=map(int,input().split())
c=list(map(int,input().split()))
c.sort()
i=0
total=0
while True:
    if b<c[i]:
        print(total)
        break
    elif i==a-1:
        if b==c[i]:
            print(total+1)
        else:
            print(total)
        break
    else:
        total+=1
        b=b-c[i]
        i+=1

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

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

Solution (Python):



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


if __name__ == "__main__":
    main()

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

ans = 0
for i, v in enumerate(a):
    x -= v
    if i == n - 1:
        if x == 0:
            ans += 1
        break
    else:
        if x >= 0:
            ans += 1
            continue
        else:
            break

print(ans)

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

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

a.sort()

count=0
 
if x<a[0]:
    print(0)
    exit()


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

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

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

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

Solution (Python):



def main():
    N, x, *A = map(int, open(0).read().split())
    A.sort()
    for i in range(N):
        x -= A[i]
        if x == 0:
            print(i + 1)
            break
        elif x < 0:
            print(i)
            break
    else:
        
        print(N - 1)


main()

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

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

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

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

count = 0
for i, child in enumerate(sorted(child_list)):
  x -= child
  if x < 0:
    break
  if (i == len(child_list) - 1) and x != 0:
    break
  count += 1

print(count)

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

a.sort()

for i in a:
  x-=i
  if x>0:
    ans+=1
    continue
  
  elif x==0:
    ans+=1
    break
    
  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=sorted(a,reverse=False)
tot=0
if sum(a)==x:
    print(len(a))
elif sum(a)<x:
    print(len(a)-1)
else:
    for i in range(N):
        tot+=a_sort[i]
        if tot==x:
            print(i+1)
            break
        elif tot<x:
            pass
        elif tot>x:
            print(i)
            break

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

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

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

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

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

Solution (Python):

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

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

print(ans)

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate, product 

from collections import deque,defaultdict,Counter
import decimal
import re
import math















import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7


from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n,x = readInts()
A = sorted(readInts())
cnt = 0

for i in range(n):
    if x > A[i] and not i == n-1:
        cnt += 1
        x -= A[i]
    elif x == A[i]:
        cnt += 1
        break
print(cnt)

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

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

Solution (Python):
n, x, *a = map(int, open(0).read().split())
a.sort()

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

Solution (Python):
def LI():
    return list(map(int, input().split()))


N, total = LI()
a = LI()
Nlist = [0]*N
a.sort()
ans = 0
if sum(a) == total:
    ans = N
elif sum(a) < total:
    ans = N-1
else:
    for i in range(N):
        if total == a[i]:
            ans += 1
            break
        elif total > a[i]:
            ans += 1
            total -= a[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 A[i] <= x:
    if i == N-1:
      if x == A[i]:
        ans += 1
    else:
      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()
ans = 0
for i, a in enumerate(A):
    if i != n-1:
        if x >= a:
            ans += 1
            x -= a
        else:
            break
    else:
        if x == a:
            ans += 1
        else:
            break
print(ans)

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

Solution (Python):
N,x = map(int,input().split())
A = sorted(list(map(int,input().split())))
if x>=2*sum(A):
    print(0)
else:
    ind = N
    for i in range(N):
        x -= A[i]
        if x<0:
            ind = i
            break
    if ind==N and x>0:
        A = sorted(A,reverse=True)
        for i in range(N):
            x -= A[i]
            if x<0:
                ind -= 1
                break
    print(ind)

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

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

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

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

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

sort_a = sorted(a)
count = 0
for i in range(1,N+1):
    if sum(sort_a[:i]) <= x:
        if i < N:
            count += 1
        else:
            pass
    else:
        break

print(count)

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

cnt = 0
flag = False
for i in a:
    if i <= x:
        x -= i
        cnt += 1
        if x == 0:
            break
    else:
        break
else:
    cnt -= 1
print(cnt)

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

cnt = 0
flag = False
for i in a:
    if i <= x:
        x -= i
        cnt += 1
        if x == 0:
            flag = True
    else:
        break
else:
    if not flag:
        cnt -= 1
print(cnt)

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

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

c=0
for i in l:
  x-=i
  if x<0:
    c+=1
    break
  else:
    c+=1

if x!=0:
  c-=1


print(c)

Solution (Python):

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

a.sort()

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

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

print(answer)

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

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

ans = 0

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

print(ans)