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

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

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

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

for i in range(len(children)):
    x-=children[i]
    if x<0:
        print(i)
        exit()

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

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:
  print(ans-1)
else:
  print(ans)

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

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

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

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

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

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

A=[int(a) for a in input().split()]

A.sort()

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

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

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

while count < n:
  if x >= list[count]:
    x -= list[count]
    ans += 1
    count += 1
  else:
    print(ans)
    break
else:
  if x == 0:
    print(ans)
  else:
    print(ans-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:
    print(i+1)
    break
  elif x<0:
    print(i)
    break
  elif i==N-1and x>0:
    print(N-1)
    break

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

ans = 0
is_broken = False
for num in sorted(a):
    if num > k:
        is_broken = True
        break
    else:
        k -= num
        ans += 1
if k != 0 and ans >= 1 and not is_broken:
    ans -= 1
print(ans)

Solution (Python):


N, x = input().split()
N = int(N)
x = int(x)

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

person = 0

break_flag = False

for a in a_list[:-1]:
    if a <= x:
        x -= a
        person += 1
    else:
        break_flag=True
        break
  
if not break_flag:
    if x == a_list[-1]:
        person += 1

print(person)

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

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

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

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

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

for ans,i in enumerate(a):
    tmp += i
    if x < tmp:
        break

if tmp == x:
    ans += 1

print(ans)

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

A.sort()
i = 0
while i < N-1 and A[i] <= x:
    x -= A[i]
    i += 1
if i == N-1:
    if A[i] == x:
        i += 1
print(i)

Solution (Python):
x=list(map(int,input().split()))
y=list(map(int,input().split()))
y.sort()
i=0
"""
while x[1]>0 and i<x[0]:
    x[1]-=y[i]
    i+=1
"""
num=0
for i in y:
    if x[1]-i>=0:
        num+=1
    x[1]-=i
if x[1]>0:
    print(num-1)
else:
    print(num)

Solution (Python):
N,x = map(int, input().split())
s = 0
for i,a in enumerate(sorted(map(int, input().split()))):
  s += a
  if x < s:
    break
if s == x:
  i += 1
print(i)

Solution (Python):
N, total = map(int, input().split())
A = list(map(int, input().split()))   
sumA = sum(A)
if total == sumA:
    print(N)
elif total > sumA:
    print(N-1)
else:
    A.sort()
    i, count = 0, 0
    while total > 0:
        total = total - A[i]
        if total >= 0: count += 1
        i += 1
    print(count)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,x = inpl()
aa = inpl()
aa.sort()

if sum(aa) == x:
    print(N)
else:
    tmp = 0
    for a in aa:
        x -= a
        tmp += 1
        if x < 0:
            print(tmp-1)
            sys.exit()
    print(N-1)

Solution (Python):
line = input().split()
N = int(line[0])
x = int(line[1])
ans = 0

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

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

while ans < n:
    temp -= a[ans]
    ans += 1
    if temp == 0:
        break
    elif temp < 0:
        ans -= 1
        break

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

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

ret = 0
for a in A:
    if x < a:
        break
    ret += 1
    x -= a

print(ret if x == 0 or ret < N else max(0, ret - 1))

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

Solution (Python):
def read():
    return [int(i) for i in input().split()]

def main():
    n, x = read()
    a = read()
    a.sort()

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

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

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

print(ans)

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

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

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

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

ans=0
for i in range(N):
	x=x-m[i]
	if x < 0:
		break
	else:
		ans+=1
        
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, v in enumerate(a):
    if x == v or (i != N - 1 and x >= v):
        ans += 1
    
    x -= v


print(ans)

Solution (Python):
def getinputdata():

    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

            else:

                flg = 0
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])
x = int(arr_data[0][1])

arr = [int(arr_data[1][i]) for i in range(n)]

mysum = sum(arr)

arr.sort()
cnt = 0
temp = 0

if x==mysum:
    
    cnt=n
    
else:
    for i in range(0,n-1):

        if arr[i] + temp <= x:

            temp += arr[i]
            cnt += 1
        else:

            break
        
print(cnt)

Solution (Python):
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 and i == len(a)-1:
    print(i+1)
  elif x < 0 or (x != 0 and i == len(a) - 1) :
    print(i)
    break

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

    a_list_sort = sorted(a_list)
    cum_sum = [sum(a_list_sort[:i+1]) for i in range(N)]
    

    if cum_sum[0] > x:
        print(0)
        return

    for i in range(N):
        
        if cum_sum[i] == x:
            print(i+1)
            return
        elif cum_sum[i] > x:
            print(i)
            return

    print(N - 1)

main()

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

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


print(nin)

Solution (Python):



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

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

A.sort()

result = 0

for a in A:
    if X >= a:
        X -= a
        result += 1
    else:
        break

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

print(result)

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

childlen = []
for part in input().split():
    childlen.append(int(part))

childlen.sort()

happy = 0
for n in range(len(childlen)):
    child = childlen[n]
    x -= child
    happy += 1
    
    if x < 0:
        print(happy - 1)
        exit(0)
    elif x == 0:
        print(happy)
        exit(0)


if x != 0:
    happy -= 1

print(happy)

Solution (Python):
hito, ame = map(int, input().split())
NeedAme = list(map(int, input().split()))
NeedAme.sort()

ans = 0
total = 0
for i in range(0, hito):
    if ((i != hito - 1) and (total + NeedAme[i] <= ame)) or ((i == hito - 1) and (total + NeedAme[i] == ame )):
        ans += 1
        total += NeedAme[i]
    else:
        break

print(ans)

Solution (Python):

import sys

n,x=map(int,raw_input().split())
a=map(int,raw_input().split())
a.sort()
b=[]
b.append(a[0])
for i in xrange(1,n):
 b.append(b[i-1]+a[i])
for i in xrange(n):
 if b[i]==x:
  print i+1
  sys.exit()
 elif b[i]>x:
  print i
  sys.exit()
print n-1

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

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

Solution (Python):
N, x = map(int, input().split())
a = sorted([int(i) for i in input().split()])
b = []
for i, v in enumerate(a):
    if i != N - 1:
        c = min(v, x)
    elif x > v:
        c = x
    else:
        c = min(v, x)
    b.append(c)
    x -= c
ans = 0
for i,j in zip(a,b):
    if i == j:
        ans += 1
print(ans)

Solution (Python):
input_lines = input().split()
N = int(input_lines[0])
x = int(input_lines[1])
input_lines = input().split()
list_a = []
for i in range(N):
    list_a.append(int(input_lines[i]))

list_a.sort()
max = 0
for i in range(N):
    current_candy = x
    current_child = 0
    for j in range(i,N):
        tmp = current_candy - list_a[j]
        if tmp >= 0:
            current_candy = tmp
            current_child += 1
    if tmp > 0:
        current_child -= 1
    if current_child >= max:
        max = current_child

print(max)

Solution (Python):
N,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
left=0
right=0
s=a[0]
answer = 0
while True:
    if left >= N or right >= N:
        break
    if s <= x:
        if s == x:
            answer = max(answer,right-left+1)
        if s < x:
            if right-left < N-1:
                answer = max(answer,right-left+1)
        right += 1
        if right < N:
            s += a[right]
        continue
    if s > x:
        s -= a[left]
        left += 1
        continue
print(answer)

Solution (Python):
import sys

input = sys.stdin.readline
n, x = map(int, input().split())
a_list = list(map(int, input().split()))
a_list.sort()
cnt = 0
flag = 0
for a in a_list:
    if x >= a:
        cnt += 1
        x -= a
    else:
        flag = 1
        break
if flag == 0 and x > 0:
    cnt -= 1
print(max(cnt, 0))

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

ans = 0

sumA = sum(A)
A.sort()

if sumA == X:
    ans = N
elif sumA < X:
    ans = N-1
else:
    for i in range(N):
        if A[i] <= X:
            X -= A[i]
            ans += 1
        else:
            break

print(ans)

Solution (Python):
s=input().split()
n=int(s[0])
x=int(s[1])
s=input().split()
l=[int(c) for c in s]
l.sort()
i=0
cnt=0
while True:
    if x>=l[i]:
        x-=l[i]
        cnt+=1
    else:
        x-=l[i]
        break
    i+=1
    if i==len(l):
        break
if x>0:
    cnt-=1
print(cnt)

Solution (Python):



def main():
    from bisect import bisect
    from itertools import accumulate

    n, x = map(int, input().split())
    a = sorted([0] + list(map(int, input().split())))
    summed_a = list(accumulate(a))
    count = bisect(summed_a, x)

    if count >= n + 1:
        count -= 1

    if summed_a[count] == x:
        print(count)
    else:
        print(count - 1)


if __name__ == '__main__':
    main()

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

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

Solution (Python):
N, X = map(int, raw_input().split())
A = map(int, raw_input().split())
A.sort()
ans = 0

for i in xrange(N):
    if X >= A[i]:
        if i < N - 1 or X == A[i]:
            ans += 1
            X -= A[i]

print ans

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

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

else:
    AS = sorted(A)
    kk = 0
    for k, a in enumerate(AS):
        if x < a:
            break
        x -= a
        kk = k + 1
    if kk == N: 
        kk = N - 1
    print(kk)

Solution (Python):
n, x = map(int, input().split())
a = sorted(map(int, input().split()))
for i in range(0, n - 1):
  k = min(a[i], x)
  a[i] -= k
  x -= k
a[-1] -= x
print(a.count(0))

Solution (Python):
def main():
    """
    2 <= N <= 100
    1 <= ai,x <= 10^9
    """
    N, x = map(int, input().split())
    *a, = map(int, input().split())

    ans = 0
    
    for _a in sorted(a):
        if _a <= x:
            ans += 1
            x -= _a

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

    print(ans)


if __name__ == '__main__':
    main()

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

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

print(ans)

Solution (Python):
N, V = list(map(int, input().split()))
C = list(map(int, input().split()))
N = len(C)

if sum(C)==V:
  print(N)
else:
  cnt = 0
  for c in sorted(C):
    if V-c>0:
      cnt += 1
      V -= c
    elif V-c==0:
      cnt += 1
      break
    else:
      break
  print(min(cnt, N-1))

Solution (Python):
def cda(N, x, s, count):
    if N > 0 and x < s[0]:
        return count
    if N == 0:
        if x > 0:
            return count - 1
        else:
            return count
    else:
        return cda(N - 1, x - s[0], s[1:], count + 1)

def agc027a():
    N, x = (int(s) for s in input().split(" "))
    a = [int(s) for s in input().split(" ")]
    answer = cda(N, x, sorted(a), 0)
    print(answer)

def main():
    agc027a()

main()

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

a.sort()

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

print(ans)

Solution (Python):
N, x = map(int, input().split())
A = list(map(int, input().split()))
 
x_tmp = x
for i, Ai in enumerate(sorted(A)):
    x_tmp -= Ai
    if x_tmp == 0:
        ans = i + 1
        break
    elif x_tmp < 0:
        ans = i
        break
    else: continue
else: ans = i
 
print(ans)

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

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

b = []
for _ in range(N):
    b.append(0)
    
c = 0

for i in range(N):
    for j in range(i+1):
        b[i] += a[j]

for k in range(N-1):
    if b[k] <= X:
        c += 1
if b[N-1] == X:
    c += 1
print(c)

Solution (Python):






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

x_tmp = x
for i, Ai in enumerate(sorted(A)):
    x_tmp -= Ai
    if x_tmp == 0:
        ans = i + 1
        break
    elif x_tmp < 0:
        ans = i
        break
    else: continue
else: ans = i

print(ans)

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

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

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

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

Solution (Python):
def a_candy_distribution_again(N, X, A):
    tmp = 0  
    for a in sorted(A):
        X -= a
        if X < 0:
            break
        tmp += 1
    ans = tmp - int(X > 0)  
    return ans

N, X = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(a_candy_distribution_again(N, X, A))

Solution (Python):
import sys

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


a.sort()
for i, ai in enumerate(a):
    x -= ai
    if x < 0:
        print(i)
        sys.exit()

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

Solution (Python):

"""
Created on Sat Sep 15 23:36:39 2018

@author: Yuki
"""

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


cnt=0
res=0
for i in range(0,N):
    cnt += A[i]
    if cnt > x:
        res = i
        break
    elif cnt == x:
        res = i+1
        break
    if i == N-1 and cnt < x:
        res = N-1
if A[0] > x:
    res=0
print(res)

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

Solution (Python):
n, x = map(int, input().split())
l = sorted(list(map(int, input().split())))
ans = 0
sum = 0
for i, v in enumerate(l):
  sum += v

  if i == (n-1) and sum < x:
    break

  if sum <= x:
    ans += 1
  else:
    break
    
print(ans)

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,*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())
c=0
for t in sorted(map(int,input().split())):
  x-=t
  if x<0:break
  c+=1
print(c-(x>0))

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

Solution (Python):
import numpy

N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
a_sum = numpy.cumsum(a)
ans = numpy.sum(a_sum <= x)

if ans == N and x not in a_sum:
    ans -= 1

print(ans)

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

Solution (Python):
def run(n, x, a):
    a = sorted(a)
    cnt = 0
    for i in range(n):
        x -= a[i]
        if x >= 0:
            cnt += 1
    if x > 0:
        cnt -= 1
    return cnt


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


if __name__ == '__main__':
    main()

Solution (Python):
N, x=map(int,input().split())
a=[int(i) for i in input().split()]
a.sort()
j=1
S=a[0]
while (S<x)and(j<N):
  S=S+a[j]
  j=j+1
if S==x:
  print(j)
else:
  print(j-1)

Solution (Python):
a = input().split()
a = [int(i) for i in a]
b = input().split()
b = [int(i) for i in b]
b = sorted(b)
output = 0
end = False

for i in range(len(b)-  1):
	if a[1] - b[i] > 0:
		a[1] += -b[i]
		output += 1
	elif(a[1] - b[i] == 0):
		output += 1
		end = True
		break
	else:
		end = True
		break
		
if end == False:
	if a[1] - b[-1] == 0:
		output += 1
		 
print(output)

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

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

Solution (Python):
N, x = map(int, input().split())
a = list(map(int, input().split()))
dp = [[]]
a.sort()
ans = 0
f = False
for b in a:
    if b <= x:
        ans += 1
        x -= b
        f = True
    else:
        f = False
if x > 0 and f:
    ans -= 1
print(ans)

Solution (Python):
in1 = input()
in2 = input()
N, x = in1.split()
N = int(N)
x = int(x)
a = list()
for i in in2.split():
  a.append(int(i))
a.sort()
count = 0
for ai in a:
  if x > ai:
    count += 1
    x -= ai
  elif x == ai:
    count += 1
    x -= ai
    break
  else:
    x -= ai
    break
if x > 0 and count > 0:
  count -= 1
print(count)

Solution (Python):



from math import *
from string import *
from itertools import *

N,X = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
happy = 0
for i in range(len(l)):
	if(X-l[i] == 0):
		X -= l[i]
		happy += 1
	elif(X-l[i] > 0 and i!=len(l)-1):
		X -= l[i]
		happy += 1
	else:
		break
print(happy)

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

    cnt = 0
    for i, y in enumerate(a):
        if x < y:
            break
        x -= y
        cnt += 1
    else:
        
        if x != 0:
            cnt -= 1
    print(cnt)

main()

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

if __name__ == '__main__':
    main()

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

Solution (Python):


from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

N, x = map(int, raw_input().split())

a = map(int, raw_input().split())

a.sort()

ans = 0

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

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

print ans

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

if len(child_list) == 1:
    if x > min(child_list):
        please_child = 0
    elif x == min(child_list):
        please_child = 1
elif len(child_list) > 1:
    nokori = x - min(child_list)
    please_child = 0 
    while nokori >=0:
        please_child +=1
        mini = min(child_list)
        child_list.remove(mini)
        if child_list == []:
            break
        if len(child_list) == 1:
            if nokori == min(child_list):
                please_child += 1
            if nokori > min(child_list):
                break
            else:
            	break
        else:    
            nokori -= min(child_list)
print(please_child)

Solution (Python):
n = [int(i) for i in input().split()]
child = n[0]
candy = n[1]

distribute_candy = sorted([int(i) for i in input().split()])
distribute_candy.sort()

delighted_child = 0

for j in range(child):
    if child - 1 == j:
        if distribute_candy[j] == candy:
            delighted_child += 1
            break
        else:
            break
    if candy - distribute_candy[j] >= 0:
        delighted_child += 1
        candy = candy - distribute_candy[j]

print(delighted_child)

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

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

Solution (Python):
n, 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
  ans += 1
if x > 0:
  if ans > 0:
    ans -= 1
print(ans)

Solution (Python):

n,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ass = 0
while len(a)>= 1:
    if a[0]<= x and len(a)>= 2:
        x = x -a[0]
        ass += 1
        del a[0]
    elif a[0] == x:
        ass += 1
        del a[0]
    else:
        break
print(ass)

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


count = 0

if sum(a_list) < x :
	count = N-1
elif sum(a_list) == x :
	count = N
else:
	for i in range(N):
		if sum(a_list_sort[:i+1]) <= x:
			continue	
		else:
			count = i
			break
print(count)

Solution (Python):
def cand(amari, a, count):
    
    if len(a)!=0:
        ma=min(a)
        a.remove(ma)
    else:
        print(count)
        exit()
    if amari>=ma:
        amari-=ma
        count+=1
        if len(a)==0 and amari!=0:
            count-=1
        
        cand(amari, a, count)
    else:
        cand(amari, a, count)




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

Solution (Python):
N = 2 
for i in range(N):
    line = input() 
    if i == 0: 
        child_count, candy_sum_orig = map(int, line.split())
    else: 
        requirement_list = list(map(int, line.split()))
satisfied_count = 0
candy_sum = candy_sum_orig
requirement_list.sort() 
for i in range(child_count): 
    requirement = requirement_list[i]
    
    if i == child_count-1: 
        if requirement == candy_sum:
            satisfied_count += 1
    else: 
        if requirement <= candy_sum:
            candy_sum -= requirement
            satisfied_count += 1
count_by_asc = satisfied_count

satisfied_count = 0
candy_sum = candy_sum_orig
requirement_list.reverse() 
for i in range(child_count): 
    requirement = requirement_list[i]
    
    if i == child_count-1: 
        if requirement == candy_sum:
            satisfied_count += 1
    else: 
        if requirement <= candy_sum:
            candy_sum -= requirement
            satisfied_count += 1

print(max(satisfied_count, count_by_asc))

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

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

print(ch)

Solution (Python):
def solver(N, x, requests):
    count = 0
    list.sort(requests)
    for req in requests:
        if x < req or x == 0:
            count += 1
            break
        x -= req
        N -= 1
        count += 1
    if N > 0 or (x > 0 and count > 0):
        count -= 1
    return count
N, x = tuple([int(n) for n in input().split(" ")])
requests = [int(n) for n in input().split(" ")]
print(solver(N, x, requests))

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

A = sorted(A)

def solve(a, x, j):
    cnt = 0
    f = False
    for i in range(j, n):
        if x >= a[i]:
            x -= a[i]
            cnt += 1
        else:
            cnt += 1
            f = True
        if f or x == 0:
            break
    if x == 0:
        return cnt
    else:
        return cnt - 1
    
res = 0
for i in range(n):
    res = max(res, solve(A[::-1], X, i))
    res = max(res, solve(A, X, i))
print(res)