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 = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()

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

low = 0
high = N - 1
most_happy = 0

while low <= high:
    i = int((low + high) / 2)
    if sum(a[0:i]) <= x:
        low = i + 1
        if i > most_happy:
            most_happy = i
    else:
        high = i - 1

print(most_happy)
exit()

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

Solution (Python):
import math
n, x = list(map(int, input().split())) 
array = list(map(int, input().strip().split()))
array.sort()
ans = 0
l = len(array)
for i in array:
    l -= 1
    x = x-i
    if l == 0:
        if x != 0:
            break
            
    if x < 0:
        break
    ans += 1
    
print(ans)

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

y = x
cnt = 0
for ai in a:
    if y - ai >= 0:
        y -= ai
        cnt += 1
if y and cnt == n:
    print(cnt - 1)
else:
    print(cnt)

Solution (Python):
nx = input().split()
an = input().split()

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

count = 0
an = list(map(int, an))
an.sort()
num = len(an) - 1
for i in range(len(an)):
    if (x >= an[i]):
        count += 1
        x = x - an[i]
        if (i == num):
            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()]
a = sorted(a)
b = [0 for i in range(n)]
count = 0
for i in range(n):
    if x - a[i] == 0:
        count += 1
        x -= a[i]
        b[i] = 1
    elif x - a[i] > 0 and i != n-1:
        count += 1
        x -= a[i]
        b[i] = 1
    """
    else:
        if x != 0 and i == n-1:
            if count > 0:
                print(count-1)
                print("aaaaa")
                exit()
            else:
                print(0)
                exit()
        elif x == 0:
            print(count)
            exit()
        else:
            print(count)
        exit()
    print(b)
    """
print(count)

Solution (Python):
n, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a = sorted(a)
b = [0 for i in range(n)]
count = 0
for i in range(n):
    if x - a[i] == 0:
        count += 1
        x -= a[i]
        b[i] = 1
    elif x - a[i] > 0 and i != n-1:
        count += 1
        x -= a[i]
        b[i] = 1
    """
    else:
        if x != 0 and i == n-1:
            if count > 0:
                print(count-1)
                print("aaaaa")
                exit()
            else:
                print(0)
                exit()
        elif x == 0:
            print(count)
            exit()
        else:
            print(count)
        exit()
    print(b)
    """
print(count)

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


total = sum(a)
num = 0

if total == x:
    num = N
elif total < x:
    num = N -1
else:
    a.sort()
    cum = 0
    for i, aa in enumerate(a):
        cum += aa
        if cum > x:
            num = i
            break

print(num)

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

al.sort()

cum = [sum(al[:i+1])for i in range(len(al))]

ans = N-1
for i in range(len(al)):
    if cum[i] == x:
        ans = i+1
        break
    elif cum[i]>x:
        ans = i
        break
print(ans)

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

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

print(res)

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

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

def f(a, x):
    if not a:
        return 0

    a.append(x)
    a = sorted(a)
    i = a.index(x)
    if i < len(a)-1:
        return len(a) - 2
    elif a[i-1] == a[i]:
        return len(a) - 2
    return f(a[:i-1], x-a[i-1])


s = sum(a)
if x == s:
    print(N)
elif x > s:
    print(N-1)
else:
    print(f(a, s-x))

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

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

a.sort()
y = 0
j = 0
for i in a:
    y += i
    if y > x: break
    j += 1
if y < x: j -= 1
print(j)

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

N = l1[0]
x = l1[1]

i = 0
s = 0

A.sort()

while True:
    if x < A[i]:
        break
    if i == N-1:
        if A[i] == x:
            s = s + 1
        break
    x = x - A[i]
    i = i + 1
    s = s + 1


print(s)

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

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

def func():
    cummulative_sum = 0
    for index, value in enumerate(A):
        cummulative_sum += value
        if cummulative_sum > x:
            return index

    if cummulative_sum != x:
        return len(A) - 1
    else:
        return len(A)

ans = func()

print(ans)

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

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

def distributeCandy(a):

    stock = int(x)
    result = 0

    for i in a:
        if stock < i:
            print(result)
            return

        if stock == 0:
            result += 1
            print(result)
            return

        result += 1
        stock -= i

    if stock == 0:
        print(result)
    else:
        print(result - 1)

distributeCandy(a)

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


if __name__ == '__main__':
    main()

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

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

Solution (Python):
from sys import stdin


def main():
    N, x = [int(x) for x in stdin.readline().rstrip().split()]
    a = [int(x) for x in stdin.readline().rstrip().split()]
    aa = sorted(a)
    xx = x
    count = 0
    for i in aa:
        if i <= xx:
            xx -= i
            count += 1
        else:
            xx = 0
            break
    if xx != 0:
        count -= 1
    print(count)


if __name__ == '__main__':
    main()

Solution (Python):
N,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans = 0
judge = [False for i in range(N)]
True_X=x

for i in range(N):
    if x-a[i]>=0:
        judge[i]=True
        x-=a[i]
temp_count=0
for i in range(N):
    if judge[i]:
        temp_count+=1

if sum(a)<True_X:
    print(temp_count-1)
else:
    print(temp_count)

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

Solution (Python):

"""
Created on Sat Sep 15 21:08:34 2018

@author: ogura
"""

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

cnt = 0
for i in range(len(b)):
    cnt += 1
    x = x - b[i]
    if x < 0:
        break

if x != 0:
    cnt = cnt -1;
    
print(cnt)

Solution (Python):

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

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

a = sorted(a)

xnum = 0
total = 0
for ax in a:
    total = total + ax
    if (total <= x):
        xnum = xnum + 1

if (total < x):
    xnum = xnum - 1
print(xnum)

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

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

lis = []
lis = input().split()
list = [int(item) for item in lis]
list.sort()
num = len(list)
count = 0
for l in range(num):
    x = x - list[l]
    count += 1
    if x <= 0:
        break

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

Solution (Python):
from sys import stdin, stdout
from itertools import accumulate
from bisect import bisect

input = lambda: stdin.readline()

def main():
    N, X = map(int, input().split())
    A = list(map(int, input().split()))

    A.sort()
    a = list(accumulate(A))
    n = bisect(a, X)
    if n == N and a[n-1] != X:
        print(n - 1)
    else:
        print(n)

main()

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

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

arr.sort()
cnt = 0
for ele in arr:
    if x < ele:
        break
    x -= ele
    cnt += 1

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

print(cnt)

Solution (Python):

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


sum = 0
answer = 0
just = 0
for i,candy in enumerate(ls_candy):
    sum += candy
    if x > sum:
        answer = i
    elif x < sum:
        answer = i
        break
    else:
        answer = i+1
        break
print (answer)

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

happy=0
a.sort()

for i in range(N):
    
    if a[i] > x:
        break

    else:
        x=x-a[i]
        happy=happy+1

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

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

for i in range(N):
	for j in range(i,0,-1):
		if a[j-1] > a[j]:
			temp = a[j-1]
			a[j-1] = a[j]
			a[j]=temp
			
while x > 0:
	x -= a[count]
	count += 1
	if N==count:
		break
if x==0:
	print(count)
else:
	print(count-1)

Solution (Python):


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

cnt = 0
if x < an[0]:
    cnt = 0
elif sum(an) < x:
    cnt = len(an) - 1
elif sum(an) == x:
    cnt = len(an)
else:
    cnt = 0
    for a in an:
        if a <= x:
            x -= a
            cnt += 1

print(cnt)

Solution (Python):
import sys
import bisect
import itertools as it
def LI(): return [int(x) for x in sys.stdin.readline().split()]


n, x = LI()
a = LI()
a.sort()
if x == sum(a):
    print(n)
elif x > sum(a):
    print(n-1)
else:
    i = bisect.bisect_right([y for y in it.accumulate(a)], x)
    print(i)

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

a.sort()

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

Solution (Python):
import sys

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


B = sorted(A)
s = sum(A)

if x > s:
    
    
    print(n-1)
    sys.exit(0)
elif x == s:
    
    print(n)
    sys.exit(0)

for i in range(n-1,0,-1):
    
    v = sum(B[0:i])
    
    if v <= x: break

if i == 1:
    if B[0] == x:
        print(1)
    else:
        print(0)
    sys.exit(0)

print(i)

Solution (Python):
N, x = map(int, input().split())
alist = list(map(int, input().split()))
alist.sort()
 
def counter(x, alist):
  count = 0
  while x > 0:
      if alist:
          tmp = alist.pop(0)
          x = x - tmp
          if x == 0:
              return count + 1
          elif x > 0:
              count += 1
          else:
              return count
      else:
          return count - 1
print(counter(x, alist))

Solution (Python):
N, M = map(int, raw_input().split())
a = map(int, raw_input().split())

a.sort()

sum = 0
itr = 0
for i in range(N):
  sum = sum+a[i]
  if sum >= M:
    itr = i
    break
    
    
if sum < M:
  print N-1
elif sum == M:
  print itr+1
elif sum > M:
  print itr

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

a = sorted(a)
c = 0
for _a in a:
	x -= _a
	if x >= 0:
		c += 1
	else:
		break
		
if x > 0:
	c -= 1
print c

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

Solution (Python):

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

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

Solution (Python):
import numpy as np

inputs = raw_input().replace("\n", "").split(" ")
N, x = map(int, inputs)
inputs = raw_input().replace("\n", "").split(" ")
a_list = np.asarray(sorted(map(int, inputs)))

a_sum = np.sum(a_list)

if a_sum < x:
    print N - 1
elif a_sum == x:
    print N
else:
    if a_list[0] > x:
        print 0
    else:
        b_sum_list = np.asarray([np.sum(a_list[:i+1]) for i in xrange(N) ])
        max_index = np.max(np.where(b_sum_list <= x)[0])
        print max_index + 1

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

A.sort()

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

print(ans)

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

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

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

if count == N :
	if k>0:
		count -= 1
	print(count)
else:
	print(count)

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

print(count)

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

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

print(ans)

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

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

count = 0
ans = 0
for i in a:
	if x >= i:
		x = x - i
		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()))
a.sort()
m=0
i=0
if a[0]>x:
    print(0)
else:
    while m<x and i<N and (m+a[i])<=x:
        m += a[i]
        i +=1
    if i==N and m!=x:
        i -=1
        print(i)
    else:
        print(i)

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

Solution (Python):
NX = input()
NX = NX.split(' ')
N = int(NX[0])
x = int(NX[1])
A = input()
A = list(map(int, A.split(' ')))
sorted_a = sorted(A)
s = 0

cum_sum = [0] * (len(sorted_a))
for i, a in enumerate(sorted_a):
    s = s + a
    cum_sum[i] = s

checker = True
for i, s in enumerate(cum_sum):
    if s == x:
        print(i+1)
        checker = False
        break
    elif s >= x:
        print(i)
        checker = False
        break

if checker:
    print(i)

Solution (Python):


n, x = map(int, input().split())
sa = input().split()
a = []

for s in sa:
    a.append(int(s))

a = sorted(a)

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

if dif > 0:
    ans -= 1

print(ans)

Solution (Python):
import numpy as np

N, x = list(map(int, input().split()))
a = np.asarray(list(map(int, input().split())))
a = np.sort(a)
s = 0
for i in range(1, N):
    if np.sum(a[:i]) <= x:
        s += 1
if np.sum(a) == x:
    s += 1
print(s)

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

B = [0]*N



zan=x

for i in range(N):
	a=A[i]
	if zan>=a:
		B[i]=a
		zan-=a
	else:
		B[i]=zan
		zan=0
		break

if zan>0:
	B[-1]+=zan
	zan=0

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


print(ans)

Solution (Python):
iN,iX = [int(x) for x in input().split()]
aL = [int(x) for x in input().split()]
aL.sort()
iNec = sum(aL)


if iNec < iX :
    print( iN - 1 )


else:
    iCounter = 0
    for iE in aL:
        if iX >= iE:
            iX -= iE
            iCounter += 1
        else:
            break
    print(iCounter)

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

a = [int(i) for i in input().split()]
total = 0
for  a_ in a:
    total  += a_
a.sort()
c = 0
if total > x:
    i = 0
    while(True):
        x -= a[i]
        i+=1
        if x < 0:
            print(c)
            break
        c +=1
elif total < x:
    print(N-1)

else:
    print(N)

Solution (Python):
import sys
from collections import deque
import copy

from math import *

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])]
    A = []
    A_dic = {}
    input_raw = read_func().strip().split()
    for i in range(N):

        a = int(input_raw[i])
        A.append(a)
        if a in A_dic:
            A_dic[a] += 1
        else:
            A_dic[a] = 1
    A.sort()
    max_count = 0
    for i in range(N):
        count = 0
        x_tmp = x
        for j in range(i, N):
            if x_tmp - A[j] >= 0:
                if j < N - 1:
                    count += 1
                else:
                    if x_tmp == A[j]:
                        count += 1
            x_tmp -= A[j]
        
        max_count = max(max_count, count)


    print max_count



if __name__ == '__main__':
    main()

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

a.sort()

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

Solution (Python):
headData = input().split()
candyTotal = int(headData[1])
childList = [ int(n) for n in input().split()]
childList.sort()
childTotal = sum(childList)

if candyTotal == childTotal:
    print(len(childList))
elif candyTotal > childTotal:
    print(len(childList)-1)
else:
    answer=0
    childSum=0
    for child in childList:
        childSum = childSum + child
        if childSum > candyTotal:
            print(answer)
            exit()
        else:
            answer = answer + 1
    print(answer-1)

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

Solution (Python):

"""
Created on Sat Sep 15 20:49:02 2018
AGC027A
@author: maezawa
"""

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

a.sort()
b = []
b0 = 0
for i in range(n):
    b0 += a[i]
    b.append(b0)

if b[0] > x:
    ans = 0
elif b[-1] == x:
    ans = n
elif b[-1] < x:
    ans = n-1
else:
    i = 0
    while True:
        if x == b[i]:
            ans = i + 1
            break
        elif x < b[i]:
            ans = i
            break
        i += 1

print(ans)

Solution (Python):
import sys

n, x = [int(_) for _ in input().split()]
l = [int(_) for _ in input().split()]

l.sort()

for i in range(len(l)):
    if i == 0:
        continue
    else:
        l[i] = l[i-1] + l[i]

if x < l[0]:
    print(0)
    sys.exit()

for i in range(0, len(l)):
    if i != len(l)-1:
        if l[i] <= x < l[i+1]:
            print(i+1)
            sys.exit()
    else:
        if x == l[i]:
            print(i+1)
        else:
            print(i)

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

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

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

a.sort()
sum = 0
ans = 0

for i in a:
	sum += i
	if sum <= x:
		ans += 1
	else:
		break
if ans == n:
	if sum < x:
		ans -= 1
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())
an = list(map(int, input().split()))

an.sort()


ans = 0

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


if x > 0:
    if ans > 0:
        if ans == len(an):
            ans -=1
        else:
            pass
    else:
        ans = 0

print(ans)

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

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

s = 0
cnt = 0
ais.sort()

for ai in ais:
    if(s+ai>x):
        break
    else:
        s += ai
        cnt += 1

if((cnt==N) & (s < x)):
    cnt -= 1

print(cnt)

Solution (Python):
from itertools import accumulate

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

a.sort()
cnt = 0
for suma in accumulate(a):
    if suma > x:
        break
    cnt += 1
else:
    if suma != x:
        cnt -= 1

print(cnt)

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

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

ans = 0

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

print(ans)

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

ans = 0

arr.sort()

for c in arr:
    if x > 0:
        x -= c
        ans += 1

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

print(ans)

Solution (Python):
import numpy as np
import math





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

A.sort()

tot = 0
for i, a in enumerate(A):
    tot += a
    if tot > x:
        print(i)
        exit(0)
    elif tot == x:
        print(i+1)
        exit(0)

print(len(A)-1)

Solution (Python):

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

A = list(map(int, input().split()));


answer = 0;
check = 1;

while(check == 1):
    min = 5000000000000000;
    for i in A:
        if(i < min):
            min = i;

    if(x >= min):
        x -= min;
        answer += 1;
        A.remove(min);
    else:
        check = 0;

if(x > 0 and A == []):
    answer -= 1;

print(answer);

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

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

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

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

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

array = sorted(array)
cnt = 0
for i in range(len(array)):
    if x >= array[i]:
        if len(array)-1 == i and x != array[i]:
            break
        cnt += 1
        x -= array[i]
    else:
        break
print(cnt if x == 0 else cnt)

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

a = sorted(a)
sum = 0
count = 0
for i in a:
    sum += i
    if sum > x:
        break
    else:
        count += 1
if sum < x:
    count -= 1
print(count)

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

for num in a:
    if num<=x:
        x-=num
        res+=1
    else:
        break
if x != 0 and res == N:
    res-=1
print(res)

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

children = sorted(children)
for j,i in enumerate(children):
  if x < i:
    break
  elif x == i:
    ans += 1
    break
  elif j == len(children)-1:
    break
  else:
    x -= i
    ans += 1
    
print(ans)

Solution (Python):

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

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

if i==n-1 and not flag and x>0:
    ret = max(0,ret-1)
print(ret)

Solution (Python):
import sys
import socket

if socket.gethostname() in ['N551J', 'F551C']:
    sys.stdin = open('a1.in')


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


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    n, x = read_int_list()
    a = read_int_list()
    a.sort()
    if sum(a) == x:
        return n
    res = 0
    for i in range(n):
        if sum(a[:i]) <= x:
            res = i
    return res


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()

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

Solution (Python):
def min(list):
	min=10000000000
	for i in range(len(list)):
		if list[i]<min:
			min=list[i]
		else:
			pass
	return min

N,x=map(int,input().split())
a=list(map(int,input().split()))
C=0
p=0
while C<x:
	if p==N:
		C=x
		p=p-1
	elif C+min(a)<=x:
		C=C+min(a)
		a.remove(min(a))
		p=p+1
	else:
		C=x
print(p)

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

a.sort()

ans = 0
for v in a:
  if x < v:
    print(ans)
    break
  x -= v
  ans += 1
else:
  if x != 0:
    ans -= 1
  print(ans)

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

res = 0
sum = 0
for i in a:
    res += 1
    sum += i
    if sum>=x:
        break
if sum==x:
    print(res)
else:
    print(res-1)

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

Solution (Python):
na = lambda: list(map(int, input().split()))
n, x = na()
a = sorted(na())
ans = 0
if a[0] > x:
    print(0)
    exit()
for i in a:
    if i > x:
        x = 0
        break
    x -= i
    ans += 1
if x != 0:
    ans -= 1
print(ans)

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

count = 0
for ai in a:
	if x >= 0 and x < ai:
		break
	else:
		x -= ai
		count += 1
else:
	if x > 0:
		count -= 1

print(count)

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

A.sort()
head=0
ans=0

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