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())
a = sorted(list(map(int, input().split())))
ans = 0
snack_sum = 0

while ans < N:
    snack_sum += a[ans]
    if snack_sum > x:
        break
    else:
        ans += 1

if ans == N:
    if snack_sum != x:
        print(ans - 1)
        exit()
print(ans)

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

a.sort()

result = 0

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

Solution (Python):
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

n,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
cnt = 0
for i in range(len(a)):
    if x>=a[i]:
        cnt += 1
    x -= a[i]
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

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

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
mo = 10**9+7

def main():
	n,x = MI()
	a = LI()
	a.sort()
	ans=0
	for i,aa in enumerate(a,1):
		if(x>=aa and i!=n):
			x-=aa
			ans+=1
		if(i==n and x==aa):
			ans+=1
	print(ans)

if __name__ == '__main__':
	main()

Solution (Python):
def myAnswer(N:int,x:int,A:list) -> int:
   if(sum(A)==x): return N
   A.sort()
   counter = 0
   hantei = True
   for n,a in enumerate(A):
      if(a > x):
         hantei = False
         break
      elif(a == x):
         counter += 1
         return counter
      elif(a < x):
         x -= a
         counter += 1

   if(x != 0 and counter != 0 and hantei ):
      counter -=1
   return counter

def modelAnswer():
   tmp=1
def main():
   N,x = map(int,input().split())
   A = list(map(int,input().split()))
   print(myAnswer(N,x,A[:]))


if __name__ == '__main__':
   main()

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

Solution (Python):

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

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

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

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

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

print(ans)

Solution (Python):
import numpy as np
N, x = map(int, input().split())
a = list(map(int, input().split()))
a = np.sort(np.array(a))
cumul = np.cumsum(a)
sign = np.sign(cumul - x)

if np.all(sign == -1):
    print(N - 1)
else:
    print(np.sum(sign <= 0))

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

Solution (Python):
N, x = map(int, input().split())
a = list(map(int, input().split()))
sort_a = sorted(a)
count = 0
for y in range(len(sort_a)):
    if y != len(sort_a) - 1:
        if sort_a[y] <= x:
            x -= sort_a[y]
            count += 1
        else:
            break
    else:
        if sort_a[y] == x:
            count += 1

print(count)

Solution (Python):
import bisect,collections,copy,itertools,math,numpy,string
def I(): return int(input())
def S(): return input()
def LI(): return list(map(int,input().split()))
def LS(): return list(input().split())

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

Solution (Python):
N,x = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a)
count = 0
while(x >= 0):
  if(count == N):
    break
  tmp = a.pop(0)
  if(x >= tmp):
    x = x - tmp
    count += 1
  else:
    break
if(count == N and x != 0):
  count -= 1
print(str(count))

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

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

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

ans = 0
for i in range(N):
    if sum(A[:i]) <= x:
        ans = i
print(ans)

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

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

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

Solution (Python):
n,x = map(int,input().split())
a = list(map(int,input().split()))
c = 0
a.sort()
for i in a:
  c += 1
  x -= i
  if x < 0:
    c -= 1
if x > 0:
  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(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())
l=sorted(list(map(int,input().split())))
if sum(l)<=x:print(n-int(sum(l)!=x));exit()
if l[0]>x:print(0);exit()
d=[]
now=0
for i in l:
    now+=i;d.append(now)
from bisect import bisect_left as bl,bisect_right as br

print(br(d,x))

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

Solution (Python):
from sys import stdin

n, x = map(int, stdin.readline().rstrip().split())
a = list(map(int, stdin.readline().rstrip().split()))

ans = 0
a.sort()
for i, ai in enumerate(a):
    if x < ai:
        break
    if i == n - 1:
        if x > ai:
            break
    x -= ai
    ans += 1

print(ans)

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

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt
from functools import lru_cache, reduce
INF = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline


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 -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 __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


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 lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)


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

b = [0] * n
for i in range(n - 1):
    if x == 0:
        continue
    b[i] = min(x, a[i])
    x -= min(x, a[i])
b[-1] = x
ans = 0
for i in range(n):
    if a[i] == b[i]:
        ans += 1
print(ans)

Solution (Python):
N, x = map(int, input().split())
A = sorted(list(map(int, input().split())))
S = [0]
for i in range(N):
    S.append(S[i] + A[i])

l = -1
r = N+1
while r - l > 1:
    m = l + (r-l)//2
    if S[m] > x:
        r = m
    else:
        l = m
print(l - (l == N and S[l] < x))

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

print(ans - (ans == N and S != x))

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

flag = 0

if x > sum(a):
  print(N-1)
elif x == sum(a):
  print(N)
else:
  for i in range(N):
    if x < sum(a[:i]):
      flag = 1
      print(i-1)
      break
  if flag == 0:
    print(N-1)

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

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

if not x == 0:
  cnt -= 1

print(cnt)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_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 a[i] > x:
		break
	else:
		x -= a[i]
		ans += 1
else:
	if x == a[-1]:
		ans += 1
print(ans)

Solution (Python):

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

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

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

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

for i in a:
    wa += i
    cnt += 1
    if wa > x:
        print(cnt - 1)
        exit()
        
    elif wa == x:
        print(cnt)
        exit()
print(cnt - 1)

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

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

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

ans = 0
A.sort()

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

print(ans)

Solution (Python):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
n,x = iim()
A = sorted(iil())
count = 0
for i in A:
    x -= i
    count += 1
    if x < 0:
        print(count-1)
        exit()
    elif x == 0:
        print(count)
        exit()
print(count-1)

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

L = sorted(L)

total = 0
for i in range(N):
    if M - int(L[0]) >= 0:
        M -= int(L[0])
        total += 1
        L.pop(0)

if total == N and not M == 0:
    total = N - 1
        
print(total)

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

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

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

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

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

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




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

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

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

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

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

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


A = sorted(A)
t = 0
num = 0
if sum(A) < x:
    print(n - 1)
else:
    for i in A:
        if t + i <= x:
            t += i
            num += 1
        else:
            break
    print(num)

Solution (Python):
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') 
def gcd(a,b):return fractions.gcd(a,b) 
def lcm(a,b):return (a*b) // fractions.gcd(a,b) 
def iin(): return int(sys.stdin.readline()) 
def ifn(): return float(sys.stdin.readline()) 
def isn(): return sys.stdin.readline().split() 
def imn(): return map(int, sys.stdin.readline().split()) 
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) 
def fmn(): return map(float, sys.stdin.readline().split()) 
def iln(): return list(map(int, sys.stdin.readline().split())) 
def iln_s(): return sorted(iln()) 
def iln_r(): return sorted(iln(), reverse=True) 
def fln(): return list(map(float, sys.stdin.readline().split())) 
def join(l, s=''): return s.join(l) 
def perm(l, n): return itertools.permutations(l, n) 
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) 
def comb(l, n): return itertools.combinations(l, n) 
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) 
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N,x = imn()
a = sorted(iln())

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

Solution (Python):

def inputlist(): return [int(j) for j in input().split()]
from collections import Counter


N,x = inputlist()
a = inputlist()
a.sort()
count=0
for i in range(N):
    x -=a[i]
    if x < 0:
        print(count)
        exit()
    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()
cnt = 0
if x > sum(A):
    print(n-1)
else:
    for i in range(n):
        if (x - A[i]) >= 0:
            x -= A[i]
            cnt += 1
        else:
            break
    print(cnt)

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

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

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

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

print(cnt)

Solution (Python):
def main():
    N, x = map(int, input().split())
    a = sorted(map(int, input().split()))
    cnt = 0
    for i in range(N):
      if a[i] <= x:
        cnt += 1
        x -= a[i]
      else:
        break
    if cnt == N and x > 0:
      cnt -= 1
    print(cnt)
    
if __name__ == "__main__":
    main()

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

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

a.sort()
i = 0
if (sum(a) < x):
    i = -1
while i < n:
    x -= a[i]
    if (x < 0):
        break
    i += 1

print(i)

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

Solution (Python):

import sys


def solve(N: int, x: int, a: "List[int]"):
    a.sort()
    answer = 0
    for i in range(N):
        if x >= a[i]:
            x -= a[i]
            answer += 1
        else:
            x -= a[i]
            break
    if x > 0:
        answer -= 1
    print(answer)
    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):



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


a_list = sorted(a_list)
person_num = 0


for i in range(len(a_list)):
    a = a_list[i]
    x = x - a
    if x >= 0:
        person_num += 1


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

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

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

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

else:
    for i in a:
        x -= i
        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 in range(N):
    x -= A[i]
    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()

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

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

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

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


def main():
    children, cookies = map(int, input().split())
    target = sorted(list(map(int, input().split())))
    sum_target = sum(target)
    if sum_target < cookies:
        print(children - 1)
    elif cookies < target[0]:
        print(0)
    else:
        accumulate_target = list(accumulate(target))
        print(bisect_right(accumulate_target, cookies))


if __name__ == '__main__':
    main()

Solution (Python):
import sys

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

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

a.sort()


























if x == sum(a):
    print("{}".format(n))
else:    
    cnt_candy = 0
    cnt_children = 0

    for index, item in enumerate(a):
        cnt_candy += item
        if x >= cnt_candy:
            cnt_children = index + 1

    if x > sum(a):
        print("{}".format(n-1))
    else:
        print("{}".format(cnt_children))

Solution (Python):
import sys

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

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

a.sort()

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

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

print("{}".format(cnt_children))

Solution (Python):
import sys

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

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

a.sort()














cnt_candy = 0
cnt_children = 0
for item in a:
    if cnt_candy < x:
        cnt_candy += item
        cnt_children += 1

if cnt_candy != x:
    cnt_children -= 1

print("{}".format(cnt_children))

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

Solution (Python):
N,x=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
cnt=0
while x>0:
    
    if x>=A[cnt]:
        x-=A[cnt]
        cnt+=1
    else:
        break
    if len(A)==cnt:
        if x>0:
            cnt-=1
        break
print(cnt)

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


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

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

print(ans)

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

"""
「ちょうど」でｷｬｯｷｬ
"""

A.sort()

from itertools import accumulate

A = tuple(accumulate(A))

ans = N - 1
for i,a in enumerate(A):
    if x > a:
        pass
    elif x == a:
        ans = i + 1
        break
    else:
        ans = i
        break

print(ans)

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

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

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

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

Solution (Python):
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=a[0]
y=a[1]
b.sort()
i=0
k=0
while i ==0:
	t=b[0]
	if y>=t:
		k=k+1
		y=y-t
		del b[0]
	else:
		i=1
	if x==k:
		i=1
if y>0 and x==k:
	k=k-1
print(k)

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

if __name__ == "__main__":
    main()

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

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

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


A.sort()


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

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

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, ai in enumerate(a):
    x -= ai
    if (x > 0 and i != len(a)-1) or x == 0:
        ans += 1
    else:
        break
print(ans)

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

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

Solution (Python):
n, candy = list(map(int, input().split()))
nums = list(map(int, input().split()))

nums.sort()

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


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