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

Solution (Python):
import bisect

N, x = map(int, input().split())
A = list(map(int, input().split()))
S = [0] * (N + 1)
A.sort()

for i, a in enumerate(A):
    S[i + 1] = S[i] + a

res = bisect.bisect_right(S, x) - 1
if res == N and S[-1] != x:
    print(res - 1)
else:
    print(res)

Solution (Python):



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

    count = 0
    i = 0
    while x > 0 and i < N:
        if a[i] <= x:
            count += 1
            x -= a[i]
        else:
            break
        i += 1

    if i == N and x != 0:
        count = max(0, count - 1)

    print(count)


if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
from sys import stdin
N,x=[int(x) for x in stdin.readline().rstrip().split()]
data=[int(x) for x in stdin.readline().rstrip().split()]
data=sorted(data)
ans=0
if data[0] > x:
    print(0)
else:
    for i in data:
        x=x-i
        if x < 0:
            break
        ans+=1
    if x > 0 and x!=0 and ans !=1:
        ans-=1
    print(ans)

Solution (Python):

a=raw_input();
lt=a.split(' ')
n=int(lt[0])
x=int(lt[1])
b=raw_input()
lt=b.split(' ')
ar=[]
for i in range(0,n):
	ar.append(int(lt[i]))

ar.sort()
v=0
for i in range(0,n):
	if x<=0:
		break
	else:
		x-=ar[i]
		v+=1

if x!=0:
	v-=1
print(v)

Solution (Python):
n,x = (int(i) for i in input().split())
a = sorted([int(i) for i in input().split()])
cnt = 0
if x > sum(a):
  cnt -= 1
for j in a:
  if x >= j:
    x -= j
    cnt+=1
print(cnt)

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

Solution (Python):
from itertools import accumulate
from bisect import bisect_right
n,x=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
S=list(accumulate(A))
i=bisect_right(S,x)
if i!=n:
    print(i)
else:
    if S[-1]==x:
        print(n)
    else:
        print(n-1)

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

Solution (Python):


N, x = map(int, input().split())
aList = map(int, input().split())
sortedAList = sorted(aList)

cnt = 0
for i in range(0, len(sortedAList)):
	if x >= sortedAList[i]:
		if i + 1 != len(sortedAList) or x == sortedAList[i]:
			cnt += 1
			x   -= sortedAList[i]
		else:
			break
	else:
		break
	
print(cnt)

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
    else:
        ans += 1

print(ans-1) if x > 0 else print(ans)

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

if x > sum(a):
  ans = n-1
elif x == sum(a):
  ans = n
else:
  judge = 0 
  for i in a:
    judge += i
    if judge > x:
     break
    ans += 1
print(ans)

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

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

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

Solution (Python):
a,b= map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
if sum(ar) == b:
    print(a)
elif sum(ar) < b:
    print(a-1)
else:
    br = []
    for r in ar:
        if r <= b:
            br.append(r)
    if len(br) == 0:
        print(0)
    else:
        br = sorted(br,reverse=True)
        while True:
            if sum(br) > b:
                del br[0]
            else:
                print(len(br))
                break

Solution (Python):
import bisect

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

A = sorted(A)

for i in range(len(A)-1):
    A[i+1] += A[i]

ans = 0
ind = bisect.bisect_right(A, x)
if ind == 0:
    ans = 0
elif ind >= N:
    if A[-1] == x:
        ans = N
    else:
        ans = N-1
else:
    ans = ind
print(ans)

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:
        break
    ans += 1

if x > 0:
    ans -= 1

print(ans)

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

count = 0

for i in range(N):
    if len(a) <= 1:
        if a[0] == x:
            count += 1
        break
    
    n = min(a)
    if x < n:
        break
    
    x -= n
    a.pop(a.index(n))
    count += 1
    
print(count)

Solution (Python):


import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, initial=1)
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, X = MAP()
aN = LIST()

aN.sort()
sm = sum(aN)
if sm < X:
    print(N-1)
elif sm == X:
    print(N)
else:
    x = X
    for i in range(N):
        x -= aN[i]
        if x < 0:
            print(i)
            exit()

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

li.sort()

child = 0
for a in li:
    x -= a
    if x < 0:
        break
    child += 1
if x > 0:
    child -= 1

print(child)

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

li.sort()

child = 0
for a in li:
    x -= a
    if x < 0:
        break
    child += 1
if x > 0:
    child -= 1

print(child)

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

Solution (Python):
import sys


def r(n, x, al):
    al.sort()
    for i in range(n):
        if x < al[i]:
            break
        elif x >= al[i]:
            x -= al[i]
        if x == 0:
            i += 1
            break

    return i


def main():
    input = sys.stdin.readline
    n, x = list(map(int, input().split()))
    al = list(map(int, input().split()))
    print(r(n, x, al))


if __name__ == '__main__':
    main()

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

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

Solution (Python):
import sys
n, x = map(int, input().split())
kids = list(map(int, input().split()))
kids.sort()
joy = 0
for k in kids:
  if (x >= k):
    x -= k
    joy += 1
  else:
    print(joy)
    sys.exit()
if (x > 0):
  joy -= 1
print(joy)

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

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

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

Solution (Python):
n, x = map(int, raw_input().split())
a = map(int, raw_input().split())
a.sort()
give = a[::]

for i in range(n):
    if i == n-1:
        give[i] = x
    else:
        give[i] = min(x, a[i])
        x -= give[i]

print sum([give[i] == a[i] for i in range(n)])

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

a.sort()

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

if ans == N:
    if sum(a) != x:
        ans -= 1

print(ans)

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

for i in range(n):
    if x > 0:
        x -= A[i]
        count += 1
        
if x != 0:
    count -= 1
    
print(count)

Solution (Python):
import sys

input = sys.stdin.readline


def ii():
    return int(input())


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


N, X = il()
A = sorted(il())
if X == sum(A):
    print(N)
    exit()

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

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

Solution (Python):


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

A.sort()
candy = 0
ans = 0
for i in A:
    candy += i
    if candy <= x:
        ans += 1
if candy < x:
    ans -= 1
print(ans)

Solution (Python):
N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
num = a[0]
i = 0
if sum(a) > x:
    while num <= x:
        i += 1
        num += a[i]
    print(i)
elif sum(a) == x:
    print(N)
else:
    print(N-1)

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

A.sort()
count = 0

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

if len(A) == count and x > 0:
    count -= 1

print(count)

Solution (Python):




def  countJoyChild(haveCookie,joyMeterList):
	joyMeterList.sort()
	childsCount = len(joyMeterList)
	sendCookieRangeMax = range(0,childsCount,+1)
	sendCookieChilds = 0
	for i in sendCookieRangeMax :
		haveCookie = haveCookie-joyMeterList[i]
		if 0 <= haveCookie:
			sendCookieChilds = sendCookieChilds + 1
		else:
			break
	if 0 < haveCookie: 
		sendCookieChilds = sendCookieChilds - 1

	answer = sendCookieChilds
	return answer


if __name__ == '__main__':
	_,X = map(int,input().strip().split(' '))
	A = list(map(int,input().strip().split(' ')))
	solution=countJoyChild(X,A)
	print("{}".format(solution))

Solution (Python):




import time
from contextlib import contextmanager

@contextmanager
def timer(title):
	t0 = time.time()
	yield
	print("{} - done in {:.0f}s".format(title,time.time()-t0) )

def  countJoyChild(haveCookie,joyMeterList):
	joyMeterList.sort()
	childsCount = len(joyMeterList)
	sendCookieRangeMax = range(0,childsCount,+1)
	sendCookieChilds = 0
	for i in sendCookieRangeMax :
		haveCookie = haveCookie-joyMeterList[i]
		if 0 <= haveCookie:
			sendCookieChilds = sendCookieChilds + 1
		else:
			break
	if 0 < haveCookie: 
		sendCookieChilds = sendCookieChilds - 1

	answer = sendCookieChilds
	return answer


if __name__ == '__main__':
	_,X = map(int,input().strip().split(' '))
	A = list(map(int,input().strip().split(' ')))

	solution=countJoyChild(X,A)
	print("{}".format(solution))

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

Solution (Python):
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, x] = [int(input_raw[0]), int(input_raw[1])]
    input_raw = read_func().strip().split()
    A = []
    for i in range(N):
        A.append(int(input_raw[i]))

    A.sort()

    for i in range(len(A)):
        x -= A[i]
        if x == 0:
            print i + 1
            return
        if x < 0:
            print i
            return

    print len(A) - 1



if __name__ == '__main__':
    main()

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

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

inputs.sort()
ans = 0
limit = 0
for i in range(len(inputs)):
    if i == N - 1 and x - inputs[i] != limit:
        break
    elif x - limit >= inputs[i]:
        ans += 1
        limit += inputs[i]
    else:
        limit += inputs[i]

print(ans)

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

print(res + (x in a[p:]))

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

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

Solution (Python):
N,K = map(int, input().split())
L = list(map(int, input().split()))
L = sorted(L)
num = L[0]
i = 0
if sum(L) > K:
    while num <= K:
        i += 1
        num += L[i]
    print(i)
elif sum(L) == K:
    print(N)
else:print(N-1)

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

candy_num.sort()

sum_want = 0
num_child = 0

for i in range(N):
    sum_want += candy_num[i]
    if i == N-1 and sum_want < x:
        break
    if sum_want > x:
        break
    else:
        num_child += 1

print(num_child)

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

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

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

print(ans)

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

while x > 0 and i < n:
    x -=a[i]
    i += 1
if i == n and x > 0:
    print(n-1)
elif x ==0:
    print(i)
else:
    print(i-1)

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

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

N, x = [int(elem) for elem in fin().split()]
a_list = [int(elem) for elem in fin().split()]

a_list.sort()
rest_money = x
num_happy_kids = 0
for a in a_list:
    if rest_money >= a:
        rest_money -= a
        num_happy_kids += 1
    else:
        break
else:
    if rest_money > 0:
        num_happy_kids -= 1
print(num_happy_kids)

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

li.sort()
ans = 0

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

if x > 0:
    ans -=1

print(ans)

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

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

Solution (Python):

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

Solution (Python):
import sys


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


def next_int() -> int:
    return int(next_str())


def main() -> None:
    n, x = [next_int() for _ in range(2)]
    a = sorted([next_int() for _ in range(n)])
    ans = 0

    for i, ai in enumerate(a):
        if x < ai or (i == n - 1 and x != ai):
            break
        ans += 1
        x -= ai

    print(ans)


if __name__ == '__main__':
    main()

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 i == N - 1:
        if x == a[i]:
            ans += 1
        break
    if x >= a[i]:
        x -= a[i]
        ans +=1

print(ans)

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

Solution (Python):
N, x = [int(_) for _ in input().split()]
A = sorted([int(_) for _ in input().split()])
num = 0
ans = 0
while A:
    num += A.pop(0)
    if (num < x and A) or num == x:
        ans += 1
    else:
        break
print(ans)

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

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

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

Solution (Python):
N,x=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:
    if 0 < x and N==cnt:
        cnt-=1

print(cnt)

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

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


b.sort()

ans = 0

for i in range(N):
	if A>=b[i]:
		ans = ans+1
		A = A - b[i]
else:
	if A>0 and N==ans:
		ans = ans-1

print(ans)

Solution (Python):
n, x = input().split(" ")
a = input().split(" ")

n, x = int(n), int(x)
a = sorted([int(i) for i in a])

s = x
ret = 0
for i in a:
    if s >= i:
        ret += 1
        s -= i
        n -= 1

if s and not n:
    ret -= 1

print(ret)

Solution (Python):
n, x = input().split(" ")
a = input().split(" ")

n, x = int(n), int(x)
a = sorted([int(i) for i in a])

s = x
ret = 0
for i in a:
    if s >= i:
        ret += 1
        s -= i
        n -= 1

if s and n==0:
    ret -= 1

print(ret)

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

Solution (Python):
N,x=map(int,input().split())
Children=list(map(int,input().split()))
Children.sort(key=lambda x:x)
n=0
S=0
while n<=N-1:
  S+=Children[n]
  if S<x:
    n+=1
  elif S==x:
    n+=1
    break
  elif S>x:
    break
if S<x:
  n+=-1
print(n)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,x = LI()
    a = sorted(LI())
    r = 0
    for c in a:
        if c > x:
            x -= c
            break
        x -= c
        r += 1
    if x > 0:
        r -= 1

    return r


print(main())

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

a = 0
i = 0

list.sort()

if list[0] > x:
    print(0)

elif x > sum(list):
    print(n-1)

else:
    while x > 0 and x >= list[i]:
        x -= list[i]
        i += 1
        a += 1
        if i == n:
            break

    print(a)

Solution (Python):
def solve(n, y, b):
  b.sort()
  s = 0
  for i in range(n):
    s = s + b[i]
    if s == y:
      return i + 1
    if s > y:
      return i
  return n - 1
N, x = map(int, input().split())
a = list(map(int, input().split()))
print(solve(N, x, a))

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

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

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

a.sort()
ans = 0

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

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

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

for n in range(N):
    if n!=N-1:
        if l[n]<x:
            x-=l[n]
            ans+=1
        elif l[n]==x:
            x-=l[n]
            ans+=1
            break
        else:
            break
    else:
        if l[n]==x:
            x-=l[n]
            ans+=1
        else:
            break

print(ans)

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

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

if s == N:
	if x != 0:
		s -= 1

print(s)

Solution (Python):
import sys
from fractions import gcd


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


if __name__ == '__main__':
    main()

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

Solution (Python):
N, x = map(int, input().split())
a = sorted(map(int, input().split()))
if sum(a) < x:
    ans = -1
elif sum(a) == x:
    ans = N
else:
    ans = 0


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

Solution (Python):

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

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

ans = 0
ttl = sum(a)

if ttl < X:
    ans = N - 1
elif ttl == X:
    ans = N
else:
    s = 0
    for ax in a:
        if s + ax <= X:
            s += ax
            ans += 1
        else:
            break
print(ans)

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

b = sorted(a)

ans = 0
total = 0

for i in range(len(b)):
    if i != (len(b) - 1):
        if total + b[i] <= x:
            ans += 1
            total += b[i]
    elif total + b[i] == x:
        ans += 1
    else:
        ans += 0

print(ans)

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

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

summation = 0
for i, ai in enumerate(a):
  summation += ai
  if summation > x:
    print(i)
    exit(0)

if summation == x:
  print(N)
else:
  print(N-1)

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

Solution (Python):
N, x = map(int, input().split())
a = map(int, input().split())
a_sorted = sorted(a)
if sum(a_sorted) == x:
  print(N)
elif sum(a_sorted) <= x:
  print(N - 1)
else:
  i = 0
  a_sum = 0
  while a_sum <= x:
    a_sum += a_sorted[i]
    i += 1
  print(i - 1)

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

a.sort()

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

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

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

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

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

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

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

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

ret = 0
sm = sum(a)

if sm < x:
    ret = len(a) - 1
elif sm == x:
    ret = len(a)
else:
    a.sort()
    c = 0
    for i in a:
        c += i
        if c <= x:
            ret += 1

print(ret)

Solution (Python):
n, x = list(map(int, input().split()))
s = list(map(int,input().rstrip().split()))
s.sort()
s_sum = sum(s)
l = len(s)
flg = True

if s_sum < x:
    print(l - 1)
elif s_sum == x:
    print(l)
else:
    s.reverse()
    for ss in s:
        s_sum -= ss
        l -= 1
        if s_sum <= x:
            print(l)
            flg = False
            break

    if(flg): print(0)

Solution (Python):
n, x = list(map(int, input().split()))
s = list(map(int,input().rstrip().split()))
s.sort()
list_sum = sum(s)
flg = True
if list_sum < x: 
    print(len(s) - 1)
elif list_sum == x: 
    print(len(s))
else:
    s.reverse()
    c = len(s)
    for ss in s:
        list_sum -= ss
        c -= 1
        if list_sum <= x:
            print(c)
            flg = False
            break

    if(flg):
        print(0)

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

s.sort()
sum = 0
cnt = 0
flg = True

for ss in s:
    cnt += 1
    sum += ss

    if(sum > x):
        print(cnt-1)
        flg = False
        break

if(flg):
    if (sum < x):
        print(cnt - 1)
    else:
        print(cnt)

Solution (Python):

N,x=map(int,input().split())
children=list(map(int,input().split()))
children.sort()
fun=0 if x!=sum(children) else N
if fun==0:
    for i in range(N):
        x-=children[i]
        if x>=0:fun+=1
        else: break
    if fun==N:fun-=1
print(fun)

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

	a.sort()
	for i in range(len(a)):
		x -= a[i]
		if x < 0:
			print(i)
			return
		elif x == 0:
			print(i+1)
			return
	print(len(a)-1)
	return

if __name__ == '__main__':
	main()