Mark and Jane are very happy after having their first child. Their son loves toys, so Mark wants to buy some. There are a number of different toys lying in front of him, tagged with their prices.  Mark has only a certain amount to spend, and he wants to maximize the number of toys he buys with this money.  Given a list of toy prices and an amount to spend, determine the maximum number of gifts he can buy.

Note Each toy can be purchased only once.  

Example 

$prices=[1,2,3,4]$ 

$k=7$   

The budget is $7$ units of currency.  He can buy items that cost $[1,2,3]$ for $\boldsymbol{6}$, or $[3,4]$ for $7$ units.  The maximum is $3$ items.  

Function Description

Complete the function maximumToys in the editor below.  

maximumToys has the following parameter(s):  

int prices[n]:  the toy prices  
int k:  Mark's budget  

Returns  

int: the maximum number of toys  

Input Format

The first line contains two integers, $n$ and $\boldsymbol{\mbox{k}}$, the number of priced toys and the amount Mark has to spend. 

The next line contains $n$ space-separated integers $\textit{prices[i]}$   

Constraints

$1\leq n\leq10^5$ 

$1\leq k\leq10^9$ 

$1\leq prices[i]\leq10^9$ 

A toy can't be bought multiple times.

Sample Input
7 50
1 12 5 111 200 1000 10

Sample Output
4

Explanation

He can buy only $4$ toys at most. These toys have the following prices: $1,12,5,10$.

Source: hackerrank | Difficulty: EASY
Tags: Greedy algorithms


Solutions:
x = input()
parts = x.split()
part1 = int(parts[0])
part2 = int(parts[1])
y = input()
arr = []
y = y.split()
for i in range(0, part1):
	arr.append(int(y[i]))
arr.sort()
i = 0
j = 0
while j < part1 and part2 > arr[j]:
	part2 -= arr[j]
	j += 1
	i += 1
print(i)


import sys
(N, K) = list(map(int, sys.stdin.readline().split()))
prices = sorted(filter(lambda x: x <= K, map(int, sys.stdin.readline().split())))
n = 0
while prices and K - prices[0] > 0:
	K -= prices.pop(0)
	n += 1
print(n)


read = input().split()
N = int(read[0])
K = int(read[1])
l = input().split()
toys = []
for x in l:
	toys.append(int(x))
toys.sort()
c = 0
p = 0
while c < N and p < K:
	p += toys[c]
	c += 1
if p > K:
	c -= 1
print(c)


inp = input().split(' ')
n = int(inp[0])
cap = int(inp[1])
raw = input().split(' ')
p = []
s = 0
lmax = 0
count = 0
for i in raw:
	x = int(i)
	if x < cap:
		if s + x < cap:
			p.append(x)
			s = s + x
			count = count + 1
			if x > lmax:
				lmax = x
		elif x < lmax:
			p.remove(lmax)
			p.append(x)
			s = s - lmax + x
			lmax = max(p)
print(count)


import fileinput
stdin = fileinput.input()
money = int(next(stdin).split(' ')[1])
prices = sorted([int(p) for p in next(stdin).split(' ')])
(cost, ret) = (0, 0)
for price in prices:
	cost += price
	if cost > money:
		break
	ret += 1
print(ret)


amtBudget = [int(i) for i in input().split()]
prices = [int(i) for i in input().split()]
count = 0
i = 0
while amtBudget[1] > 0 and i < amtBudget[0]:
	indexMin = prices.index(min(prices))
	amtBudget[1] -= min(prices)
	prices[indexMin] = 10000000000
	count += 1
	i += 1
print(count - 1)


(n, k) = [int(x) for x in input().split()]
prices = [int(x) for x in input().split()]
prices.sort()
count = 0
for x in prices:
	k -= x
	if k < 0:
		break
	else:
		count += 1
print(count)


import sys
N = None
K = None
prices = []
for line in sys.stdin:
	if N is None:
		(N, K) = [int(i) for i in line.strip().split()]
		continue
	prices = [int(i) for i in line.strip().split()]
prices.sort()
total_price = 0
count = 0
for price in prices:
	total_price += price
	if total_price >= K:
		print(count)
		break
	else:
		count += 1


import fileinput

def get_line():
	return map(int, input().split(' '))

def choose_toys(money, prices):
	prices = sorted(prices)
	for i in range(len(prices) + 1):
		if sum(prices[0:i]) > money:
			return i - 1
(line_count, money) = get_line()
prices = get_line()
print(choose_toys(money, prices))


(n, k) = [int(x) for x in input().split()]
prices = sorted([int(x) for x in input().split()])
total = 0
for i in range(n):
	if k - total < prices[i]:
		print(i)
		exit()
	else:
		total += prices[i]


(count, total_cost) = input().strip().split()
prices = input().strip().split()
count = int(count)
total_cost = int(total_cost)
prices = [int(entry) for entry in prices]
prices.sort()
cost = 0
for i in range(count):
	if cost > total_cost:
		break
	else:
		cost += prices[i]
print(i - 1)


inp = input().split()
N = int(inp[0])
K = int(inp[1])
toys = input().split()
i = 0
for k in toys:
	toys[i] = int(k)
	i += 1
toys.sort()
i = 0
num = 0
while K > 0 and toys[i] <= K:
	K -= toys[i]
	num += 1
	i += 1
print(num)


import sys

def main():
	line = sys.stdin.readline()
	words = line.split()
	(n, k) = (int(words[0]), int(words[1]))
	line = sys.stdin.readline()
	words = line.split()
	numbers = list(map(int, words))
	numbers.sort()
	totalcost = 0
	count = 0
	for item in numbers:
		if totalcost + item > k:
			break
		else:
			totalcost += item
			count += 1
	print(count)
main()


raw_data = input().split(' ')
n = int(raw_data[0])
money = int(raw_data[1])
toys = 0
spent_money = 0
price = input().split(' ')
price.sort()
price_int = [int(x) for x in price]
price_int.sort()
for i in range(n):
	if spent_money + price_int[i] <= money:
		spent_money += price_int[i]
		toys += 1
print(toys)


I = lambda : map(int, input().split())
(n, k) = I()
c = 0
for z in sorted(I()):
	if z <= k:
		k -= z
		c += 1
print(c)


import sys
input = sys.stdin.readlines()
(N, K) = [int(x) for x in input[0].split()]
toys = [int(x) for x in input[1].split()]
toys = sorted(toys)
counter = 0
max_cost = 0
for toy in toys:
	if max_cost + toy <= K:
		counter += 1
		max_cost += toy
	else:
		break
print(counter)


import sys

def csum(l):
	for i in range(1, len(l)):
		l[i] += l[i - 1]
	return l
lines = sys.stdin.readlines()
(n, k) = [int(x) for x in lines[0].strip().split(' ')]
items = [int(x) for x in lines[1].strip().split(' ')]
items.sort()
cummulative_sums = csum(items)
i = 0
for s in cummulative_sums:
	if s <= k:
		i += 1
	else:
		print(i)
		break


import sys
f = sys.stdin
NK = list(map(int, f.readline().split()))
N = NK[0]
K = NK[1]
arr = list(map(int, f.readline().split()))
arr = arr[:N]
arr.sort()
sum = 0
i = 0
for item in arr:
	sum += item
	if sum > K:
		print(i)
		break
	else:
		i += 1


budget = int(input().split()[1])
prices = map(int, input().split())
prices = sorted(prices)
total_price = 0
toys = 0
for price in prices:
	total_price += price
	if total_price > budget:
		break
	toys += 1
print(toys)


temp = input().split()
n = int(temp[0])
k = int(temp[1])
temp = 0
price = input().split()
for i in range(n):
	price[i] = int(price[i])
price.sort()
while k >= price[0]:
	temp += 1
	k -= price[0]
	price.pop(0)
print(temp)


n = input()
(a, b) = n.split()
b = int(b)
l = input().split()
l = [int(i) for i in l]
l.sort()
count = 0
for i in l:
	b = b - i
	if b < 0:
		break
	count = count + 1
print(count)


(n_toys, cash) = map(int, input().split())
toys = list(map(int, input().split()))
toys.sort()
total = 0
bought = 0
for (i, price) in enumerate(toys):
	if total > cash:
		print(i - 1)
		break
	total += price


(N, K) = input().split()
N = int(N)
K = int(K)
prices = [int(i) for i in input().split()]
prices.sort()
total = 0
toys = 0
for i in prices:
	if total + i > K:
		break
	else:
		total += i
		toys += 1
print(toys)


(N, K) = map(int, input().split())
toy_prices = list(map(int, input().split()))
toy_prices.sort(reverse=True)
total = sum(toy_prices)
if toy_prices[-1] > K:
	print(0)
else:
	for i in range(N):
		if total <= K:
			print(N - i)
			break
		total -= toy_prices[i]


a = input().split()
n = int(a[0])
k = int(a[1])
b = input().split()
b = [int(x) for x in b]
b.sort()
i = 0
sum = 0
toys = 0
while sum <= k and i < len(b):
	sum = sum + b[i]
	toys = toys + 1
	i = i + 1
if sum > k:
	print(toys - 1)
else:
	print(toys)


import sys
(N, K) = map(int, input().split())
items = list(map(int, input().split()))
items.sort()
currK = 0
for (idx, elem) in enumerate(items):
	if currK + elem > K:
		break
	else:
		currK += elem
print(idx)


b = str(input())
a = b.split(' ')
num_toys = int(a[0])
cash = int(a[1])
toys = str(input())
d = toys.split(' ')
e = sorted(d, key=lambda x: int(x))
i = 0
tot = 0
while i < num_toys:
	if tot == cash:
		print(i)
		break
	elif tot > cash:
		print(i - 1)
		break
	tot += int(e[i])
	i += 1


import sys
money = int(sys.stdin.readline().split()[1])
prices = sys.stdin.readline().split()
for i in range(len(prices)):
	prices[i] = int(prices[i])
prices.sort()
count = 0
while count < len(prices) and money >= prices[count]:
	money = money - prices[count]
	count += 1
print(count)


(n, m) = input().split(' ')
n = int(n)
m = int(m)
l = []
l = input().split(' ')
for i in range(0, n):
	l[i] = int(l[i])
l.sort()
i = 0
now = -1
ans = 0
while (m >= l[i]) & (i < n):
	now = l[i]
	m = m - l[i]
	ans = ans + 1
	i = i + 1
print(ans)


__author__ = 'jonghewk'
(Num, Rupee) = input().split()
Num = int(Num)
Rupee = int(Rupee)
toys = [int(i) for i in input().split()]
toys.sort()
sum = 0
count = 0
for i in toys:
	temp = sum + i
	if temp <= Rupee:
		sum = temp
		count += 1
print(count)


x = input().split(' ')
n = int(x[0])
k = int(x[1])
y = input().split()
toys = [int(i) for i in y]
a = []
for j in toys:
	if j <= k:
		a.append(j)
b = sorted(a)
psum = 0
c = -1
while psum <= k:
	c = c + 1
	if b == []:
		break
	else:
		psum = psum + b[0]
		del b[0]
print(c)


(n, k) = (int(i) for i in input().split())
num = [int(i) for i in input().split()]
num.sort()
tmp = 0
i = 0
if n > 0:
	while i < n and tmp < k:
		tmp += num[i]
		i += 1
else:
	i = 1
print(i - 1)


(n, k) = input().split()
(n, k) = [int(n), int(k)]
a = input().split()
a = [int(a[i]) for i in range(n)]
a.sort()
sum = 0
toys = 0
i = 0
while sum < k:
	sum += a[toys]
	toys += 1
print(toys - 1)


import sys

def splitline():
	line = sys.stdin.readline().split(' ')
	return [int(x) for x in line]

def main(n, k, products):
	products.sort()
	(t, q) = (0, 0)
	for i in range(n):
		t += products[i]
		if t > k:
			break
		q += 1
	return q
(n, k) = splitline()
prod = splitline()
r = main(n, k, prod)
print(r)


import fileinput
import sys
N = ''
K = ''
Price = ''
x = 0
for line in sys.stdin:
	if x == 0:
		[N, K] = line.split(' ', 1)
	else:
		Price = line
	x = x + 1
N = int(N)
K = int(K)
Price_list = Price.split()
Price_list1 = []
count1 = 1
for x in Price_list:
	Price_list1.append(int(x))
	count1 = count1 + 1
Price_list1.sort()
if N > K:
	del Price_list1[K:]
count = 0
for p in Price_list1:
	K = K - p
	if K < 0:
		break
	count = count + 1
print(count)


n = [int(i) for i in input().split()]
k = [int(i) for i in input().split()]
k.sort()
sum = 0
j = 0
while j < n[0] and sum <= n[1]:
	sum = sum + k[j]
	j = j + 1
print(j - 1)


import string
line1 = input()
line2 = input()
itemNum = int(line1.split()[0])
totalMoney = int(line1.split()[1])
money_string_array = line2.split()
money_set = set()
money = []
for each in money_string_array:
	money.append(int(each))
money.sort()
sum_money = 0
sum_toy = 0
for each in money:
	if sum_money + each <= totalMoney:
		sum_toy += 1
		sum_money += each
	else:
		break
print(sum_toy)


import sys
(n, k) = map(int, input().split())
prices = sorted(list(map(int, input().split())))
sum = 0
ans = 0
for x in prices:
	sum += x
	if sum > k:
		print(ans)
		sys.exit()
	ans += 1
print(ans)


def main():
	pass
(N, K) = map(int, input().split(' '))
items = list(map(int, input().split(' ')))
items.sort()
total = 0
for (n, item) in enumerate(items):
	total += item
	if total > K:
		total -= item
		print(n)
		exit()
print(len(items))


inp = input()
nk = [int(x) for x in inp.split()]
in2 = input()
arr = [int(x) for x in in2.split()]
arr.sort()
c = 0
s = 0
ind = 0
while s < nk[1] and ind < nk[0]:
	if s + arr[ind] <= nk[1]:
		c += 1
		s += arr[ind]
	ind += 1
print(c)


line1 = input()
line1 = line1.split()
n = int(line1[0])
k = int(line1[1])
item_prices = input()
item_prices = item_prices.split()
for i in range(0, len(item_prices)):
	item_prices[i] = int(item_prices[i])
item_prices = sorted(item_prices)
sum = 0
count = 0
for i in item_prices:
	if sum <= k:
		sum = sum + i
		if sum <= k:
			count = count + 1
print(count)


data = input().split(' ')
toys = sorted([int(x) for x in input().split(' ')])
n = int(data[0])
k = int(data[1])
toys_count = 0
r = 0
while k > 0 and r < len(toys):
	if toys[r] <= k:
		toys_count += 1
		k -= toys[r]
	r += 1
print(toys_count)


(N, K) = input().split()
total = 0
k = 0
for i in sorted(map(int, input().split())):
	total += i
	if total < int(K):
		k += 1
	else:
		break
print(k)


x = input()
x = x.split()
a = int(x[0])
b = int(x[1])
x = input()
x = x.split()
data = []
for i in range(a):
	data.append(int(x[i]))
data.sort()
tot = 0
ans = 0
for i in range(a):
	if b > data[i]:
		tot = tot + data[i]
		ans = ans + 1
		b = b - data[i]
print(ans)


(N, K) = [int(x) for x in input().split()]
prices = [int(x) for x in input().split()]
prices.sort()
ans = 0
cur = 0
for x in prices:
	if x + cur <= K:
		ans += 1
		cur += x
	else:
		break
print(ans)


(a, b) = input().split()
a = int(a)
b = int(b)
c = input().split()
c = list(map(int, c))
c.sort()
sum = 0
count = 0
for i in c:
	sum = sum + int(i)
	count = count + 1
	if sum > b:
		break
print(count - 1)


(n, k) = input().split()
(n, k) = (int(n), int(k))
input_list = input().split(' ')
a = [int(x.strip()) for x in input_list]
a.sort()
(s, i) = (0, 0)
while s <= k:
	s += a[i]
	i += 1
print(i - 1)


(n, k) = input().split(' ')
n = int(n)
k = int(k)
p = input().split(' ')
p = list(map(int, p))
p.sort()
s = 0
c = 0
for i in range(n):
	s = s + p[i]
	if s >= k:
		break
	c = c + 1
print(c)


(N, K) = [int(x) for x in input().split()]
V = [int(x) for x in input().split()]
V.sort()
ANSWER = 0
for x in V:
	if x <= K:
		K -= x
		ANSWER += 1
print(ANSWER)


lone = input()
ltwo = input()
money = int(lone.split()[1])
toys = [int(x) for x in ltwo.split()]
toys.sort()
count = 0
for toy in toys:
	money = money - toy
	if money > 0:
		count += 1
print(count)


import sys

def TOYS():
	line1 = []
	line1 = sys.stdin.readline().rstrip().split()
	N = int(line1[0])
	K = int(line1[1])
	line2 = [int(x) for x in sys.stdin.readline().rstrip().split()]
	line2.sort()
	total = 0
	for n in range(N):
		if total + int(line2[n]) > K:
			break
		total += int(line2[n])
	sys.stdout.write(str(n))
TOYS()


def toys(n, money, array):
	array.sort()
	total = 0
	for i in range(n):
		if total <= money:
			total = total + array[i]
		else:
			return i - 1
s = input()
a = [int(i) for i in s.split()]
k = input()
l = [int(i) for i in k.split()]
n = a[0]
money = a[1]
print(toys(n, money, l))


def mergeSort(A):
	if len(A) <= 1:
		return A
	mid = int(len(A) / 2)
	A_left = mergeSort(A[:mid])
	A_right = mergeSort(A[mid:])
	return merge(A_left, A_right)

def merge(A, B):
	A_i = 0
	B_i = 0
	n = len(A + B)
	result = []
	A = A[:] + [float('inf')]
	B = B[:] + [float('inf')]
	while len(result) < n:
		if A[A_i] > B[B_i]:
			result.append(B[B_i])
			B_i = B_i + 1
		else:
			result.append(A[A_i])
			A_i = A_i + 1
	return result
(N, k) = map(int, input().split())
ar = list(map(int, input().split()))
ar = mergeSort(ar)
cost = 0
count = 0
while cost < k:
	count = count + 1
	cost = cost + ar[count]
print(count)


(size, maxsum) = [int(i) for i in input().split()]
toys = [int(j) for j in input().split()]
total = 0
count = 0
toys.sort()
for x in toys:
	if total + x <= maxsum:
		total = total + x
		count = count + 1
print(count)


first_line = input()
NK = first_line.split()
N = int(NK[0])
K = int(NK[1])
second_line = input()
p = second_line.split()
price = []
for element in p:
	price.append(int(element))
count = 0
total = 0
while total <= K:
	total = total + min(price)
	price.remove(min(price))
	if total <= K:
		count = count + 1
print(count)


(N, K) = [int(x) for x in input().strip().split(' ')]
T = sorted([int(x) for x in input().strip().split(' ')])
c = 0
while c < len(T) and T[c] < K:
	K -= T[c]
	c += 1
print(c)


def main():
	inString = input().split()
	n = int(inString[0])
	m = int(inString[1])
	cost = [int(i) for i in input().split()]
	cost.sort()
	sum = 0
	i = 0
	while sum <= m:
		sum += cost[i]
		i += 1
	print(i - 1)
main()


(n, k) = input().split()
(n, k) = [int(n), int(k)]
a = input().split()
a = [int(a[i]) for i in range(n)]
a.sort()
sum = 0
toys = 0
i = 0
while sum < k:
	sum += a[toys]
	toys += 1
print(toys - 1)


Money = int(input().split()[1])
costs = [int(x) for x in input().split()]
counter = 0
pos = 0
costs.sort()
while pos < len(costs) and Money >= 0:
	if Money - costs[pos] > 0:
		counter = counter + 1
		Money = Money - costs[pos]
	pos = pos + 1
print(counter)


def main():
	(N, K) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	A.sort()
	n = 0
	for i in A:
		if i < K:
			K -= i
			n += 1
	print(n)
main()


import sys
(N, K) = [int(x) for x in sys.stdin.readline().split()]
toys = sorted([int(x) for x in sys.stdin.readline().split()])
bought = 0
for toy in toys:
	if K - toy > 0:
		bought += 1
		K -= toy
	else:
		break
print(bought)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
while ans < n and k >= a[ans]:
	k -= a[ans]
	ans += 1
print(ans)


line_1 = input()
line_1 = line_1.split(' ')
toys = int(line_1[0])
cash = int(line_1[1])
price_array = input()
price_array = price_array.split(' ')
i = 0
while i < len(price_array):
	price_array[i] = int(price_array[i])
	i += 1
price_array.sort()
i = 0
count = 0
total = 0
if cash > price_array[0]:
	while cash >= total:
		total += price_array[i]
		i += 1
		if i > len(price_array) - 1:
			i = 0
		count += 1
count = count - 1
print(count)


from itertools import combinations
i = input()
(N, K) = [int(x) for x in i.split() if x.isdigit()]
array = sorted([int(x) for x in input().split() if x.isdigit()])
items = []
for i in array:
	items += [i]
	if sum(items) > K:
		items.pop()
		break
print(len(items))


i = input().strip().split(' ')
n = int(i[0])
s = int(i[1])
l_temp = input().strip().split(' ')
l = []
t = 0
cnt = 0
for x in l_temp:
	l.append(int(x))
l.sort()
for x in l:
	if t > s:
		print(l.index(x) - 1)
		break
	else:
		t += x


def main():
	money = int(input().split(' ')[1])
	item_str = input()
	items = list(map(int, item_str.split(' ')))
	ret_val = 0
	done = False
	while items != [] and done == False:
		item = min(items)
		if item <= money:
			if money - item > 0:
				money = money - item
				ret_val += 1
			else:
				done = True
		else:
			done = True
		items.remove(item)
	print(ret_val)
main()


(n, k) = [int(x) for x in input().split()]
price = [int(x) for x in input().split()[0:n]]
price.sort()
s = 0
for i in range(0, n):
	if s > k:
		print(i - 1)
		break
	else:
		s = s + price[i]


import sys
from collections import deque
import heapq
from math import *
from itertools import *
PI = pi
INF = 1000000000

def gl():
	return input()

def gs():
	return (x for x in input().split())

def gi():
	return int(input())

def gis():
	return [int(x) for x in input().split()]

def gf():
	return float(input())

def gfs():
	return [float(x) for x in input().split()]

def even(x):
	return x % 2 == 0

def odd(x):
	return x % 2 == 1

def dbg(s):
	print(s, file=sys.stderr)
(N, K) = gis()
prices = gis()
prices.sort()
(sum_, count) = (0, 0)
for i in range(len(prices)):
	if sum_ + prices[i] <= K:
		sum_ += prices[i]
		count += 1
print(count)


import sys

def get_max_toys(n, k, ar):
	lst = []
	lst_sum = 0
	for i in ar:
		if i <= k:
			if lst_sum + i <= k:
				lst.append(i)
				lst_sum += i
			elif max(lst) > i:
				x = max(lst)
				lst.remove(x)
				lst_sum -= x
				lst.append(i)
				lst_sum += i
	return len(lst)
raw = sys.stdin.readline().split()
n = int(raw[0])
k = int(raw[1])
raw_ar = sys.stdin.readline().split()
ar = [int(i) for i in raw_ar]
count = get_max_toys(n, k, ar)
print(count)


line = input().split()
ntoys = int(line[0])
money = int(line[1])
prices = list(map(int, input().split()))
prices.sort()
tcount = 0
for x in range(0, ntoys):
	p = int(prices[x])
	if money < p:
		break
	money = money - p
	tcount = tcount + 1
print(tcount)


x = input()
x = x.split()
money = int(x[1])
y = input()
y = y.split()
for k in range(len(y)):
	y[k] = int(y[k])
y.sort()
counter = 0
for j in y:
	money -= j
	if money < 0:
		break
	counter += 1
print(counter)


(amount, money) = [int(x) for x in input().strip().split()]
items = [int(x) for x in input().strip().split()]
items.sort()
count = 0
while True:
	money -= items.pop(0)
	if money < 0:
		break
	count += 1
print(count)


import sys

def nextLine():
	return sys.stdin.readline().strip()
(n, k) = [int(s) for s in nextLine().split(' ')]
prices = [int(s) for s in nextLine().split(' ')]
prices.sort()
toys = 0
for p in prices:
	if p > k:
		break
	toys += 1
	k -= p
print(toys)


a = input().split()
(a, b) = (int(a[0]), int(a[1]))
c = input().split()
for i in range(len(c)):
	c[i] = int(c[i])
c = sorted(c)
d = 0
for i in c:
	if i < b:
		b -= i
		d += 1
	else:
		break
print(d)


(N, K) = [int(i) for i in input().strip().split()]
ar = [int(i) for i in input().strip().split()]
ar.sort()
s = 0
for (i, e) in enumerate(ar):
	s += e
	if s > K:
		break
print(i)


a = [int(x) for x in input().strip().split(' ')]
k = a[1]
tp = [int(x) for x in input().strip().split(' ')]
tp.sort()
s = 0
for i in range(a[0]):
	if s < k:
		s += tp[i]
	else:
		s -= tp[i - 1]
		print(i - 1)
		break


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


(n, k) = [int(x) for x in input().split()]
prices = [int(x) for x in input().split()]
prices.sort()
res = 0
for p in prices:
	if k > p:
		res += 1
		k -= p
	else:
		break
print(str(res))


(n, k) = map(int, input().split())
items = sorted(map(int, input().split()))
cost = 0
for (i, item) in enumerate(items):
	cost += item
	if cost > k:
		print(i)
		break


a = input().split()
n = int(a[0])
k = int(a[1])
a = input().split()
p = [int(r) for r in a]
p.sort()
s = 0
c = 0
for j in p:
	if s + j <= k:
		s += j
		c += 1
	else:
		break
print(c)


(n, k) = [int(val) for val in input().split()]
prices = [int(val) for val in input().split()]
prices = list(sorted(prices))
sum = 0
output = 0
for e in prices:
	output += e
	if output < k:
		sum += 1
	else:
		break
print(sum)


def pairs(a, k):
	answer = 0
	spent = 0
	nums = sorted(a)
	for num in nums:
		if spent + num <= k:
			spent += num
			answer += 1
		else:
			break
	return answer
a = input().strip()
a = list(map(int, a.split(' ')))
_a_size = a[0]
_k = a[1]
b = input().strip()
b = list(map(int, b.split(' ')))
print(pairs(b, _k))


import itertools, sys
(N, K) = list(map(int, sys.stdin.readline().split()))
X = sorted(map(int, sys.stdin.readline().split()))
print(max((i + 1 for (i, x) in enumerate(itertools.accumulate(X)) if x < K)))


(n, k) = map(int, input().split(' '))
toys = sorted(map(int, input().split(' ')), key=lambda x: -x)
bought_toys = 0
while k > 0:
	toy = toys.pop()
	if k > toy:
		bought_toys += 1
		k -= toy
	else:
		break
print(bought_toys)


budget = int(input().strip().split(' ')[1])
prices = list(map(int, input().strip().split(' ')))
prices.sort()
total = 0
for toy in prices:
	budget = budget - toy
	if budget < 0:
		break
	total = total + 1
print(total)


from itertools import accumulate
k = int(input().split()[1])
a = list(accumulate(sorted(list(map(int, input().split())))))
print(sorted(a + [k]).index(k))


import sys
from itertools import islice
s = input().split(' ')
n = int(s[0])
k = int(s[1])
i = 0
lis = input().split(' ')
ar = [int(i) for i in lis]
ar.sort()
sum = 0
for i in range(n):
	if sum + ar[i] <= k:
		sum += ar[i]
	else:
		break
print(i)


c = input()
n = int(c.split(' ')[0])
k = int(c.split(' ')[1])
lis = [int(i) for i in input().split(' ')]
lis.sort()
co = 0
num = 0
for i in range(len(lis)):
	co = co + int(lis[i])
	if co <= k:
		num = num + 1
print(num)


a = [int(i) for i in input().split(' ')]
(n, r) = (a[0], a[1])
b = [int(i) for i in input().split(' ')]
b.sort()
count = 0
i = 0
while r >= 0 and i < n:
	count += 1
	r -= b[i]
	i += 1
print(count - 1)


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


def solve(L, k):
	(sum, toys) = (0, 0)
	for price in sorted(L):
		if sum + price > k:
			return toys
		else:
			toys += 1
			sum += price
	return 0
(n, k) = [int(s) for s in input().split()]
L = [int(s) for s in input().split()]
print(solve(L, k))


buffer = input().split()
buffer = list(map(int, buffer))
N = buffer[0]
K = buffer[1]
lst = input().split()
lst = list(map(int, lst))
lst.sort()
counter = -1
tot = 0
while tot <= K:
	tot += lst[counter + 1]
	counter += 1
print(counter)


(N, K) = (int(z) for z in input().split())
toys = [int(z) for z in input().split()]
toys.sort()
maxCount = 0
for i in range(N):
	if toys[i] > K:
		break
	else:
		K -= toys[i]
		maxCount += 1
print(maxCount)


import sys
raw = sys.stdin.readline().split()
totalNumberOfToys = int(raw[0])
totalMoney = int(raw[1])
data = []
raw = sys.stdin.readline().split()
for index in range(totalNumberOfToys):
	data.append(int(raw[index]))
data.sort()
toyCost = 0
for toy in data:
	toyCost += toy
	if toyCost > totalMoney:
		break
print(data.index(toy))


(n, k) = map(int, input().split())
prices = sorted(map(int, input().split()))
tot = 0
for j in range(n):
	tot += prices[j]
	if tot > k:
		print(j)
		break
else:
	print(n)


nummon = input().split()
price = input().split()
s = []
for i in price:
	i = int(i)
	s.append(i)
s.sort()
sum = int(nummon[1])
d = []
for i in s:
	if sum >= int(i):
		sum = sum - int(i)
		d.append(i)
	else:
		break
x = len(d)
print(x)


(toy_count, money) = map(int, input().split())
prices = list(map(int, input().split()))
prices.sort()
toys_bought = 0
while prices[0] <= money:
	money -= prices[0]
	prices.pop(0)
	toys_bought += 1
print(toys_bought)