The only difference between easy and hard versions is constraints.

A session has begun at Beland State University. Many students are taking exams.

Polygraph Poligrafovich is going to examine a group of $n$ students. Students will take the exam one-by-one in order from $1$-th to $n$-th. Rules of the exam are following:  The $i$-th student randomly chooses a ticket.  if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.  if the student finds the ticket easy, he spends exactly $t_i$ minutes to pass the exam. After it, he immediately gets a mark and goes home. 

Students take the exam in the fixed order, one-by-one, without any interruption. At any moment of time, Polygraph Poligrafovich takes the answer from one student.

The duration of the whole exam for all students is $M$ minutes ($\max t_i \le M$), so students at the end of the list have a greater possibility to run out of time to pass the exam.

For each student $i$, you should count the minimum possible number of students who need to fail the exam so the $i$-th student has enough time to pass the exam.

For each student $i$, find the answer independently. That is, if when finding the answer for the student $i_1$ some student $j$ should leave, then while finding the answer for $i_2$ ($i_2>i_1$) the student $j$ student does not have to go home.


-----Input-----

The first line of the input contains two integers $n$ and $M$ ($1 \le n \le 100$, $1 \le M \le 100$) — the number of students and the total duration of the exam in minutes, respectively.

The second line of the input contains $n$ integers $t_i$ ($1 \le t_i \le 100$) — time in minutes that $i$-th student spends to answer to a ticket.

It's guaranteed that all values of $t_i$ are not greater than $M$.


-----Output-----

Print $n$ numbers: the $i$-th number must be equal to the minimum number of students who have to leave the exam in order to $i$-th student has enough time to pass the exam.


-----Examples-----
Input
7 15
1 2 3 4 5 6 7

Output
0 0 0 0 0 2 3 
Input
5 100
80 40 40 40 60

Output
0 1 1 2 3 


-----Note-----

The explanation for the example 1.

Please note that the sum of the first five exam times does not exceed $M=15$ (the sum is $1+2+3+4+5=15$). Thus, the first five students can pass the exam even if all the students before them also pass the exam. In other words, the first five numbers in the answer are $0$.

In order for the $6$-th student to pass the exam, it is necessary that at least $2$ students must fail it before (for example, the $3$-rd and $4$-th, then the $6$-th will finish its exam in $1+2+5+6=14$ minutes, which does not exceed $M$).

In order for the $7$-th student to pass the exam, it is necessary that at least $3$ students must fail it before (for example, the $2$-nd, $5$-th and $6$-th, then the $7$-th will finish its exam in $1+3+4+7=15$ minutes, which does not exceed $M$).

Difficulty: EASY

Solutions:
(n, m) = map(int, input('').split())
t = list(map(int, input('').split()))
k = []
for i in range(n):
	sum = 0
	for j in range(i + 1):
		sum += t[j]
	if sum <= m:
		k.append(0)
	else:
		q = []
		for h in range(i):
			q.append(t[h])
		q.sort()
		s = len(q) - 1
		c = 0
		p = 0
		count = 0
		z = 0
		while c == 0:
			z = 0
			for e in range(p + 1):
				z = z + q[s - e]
			count += 1
			if sum - z <= m:
				k.append(count)
				break
			p += 1
for a in k:
	print(a, end=' ')


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
prefix = [0] * n
for i in range(n):
	prefix[i] = prefix[i - 1] + arr[i]
brr = []
for i in range(n):
	if prefix[i] <= m:
		print(0, end=' ')
	else:
		brr.sort()
		ct = 0
		sm = prefix[i]
		for k in range(len(brr) - 1, -1, -1):
			sm -= brr[k]
			ct += 1
			if sm <= m:
				print(ct, end=' ')
				break
	brr.append(arr[i])
print()


(n, m) = map(int, input().split())
ar = list(map(int, input().split()))
j = 0
while j != n:
	t = count = 0
	for i in range(j + 1):
		t += ar[i]
	if t < m:
		print(0, end=' ')
	else:
		ar1 = sorted(ar[0:j])
		sm = sum(ar1)
		while sm + ar[j] > m:
			sm -= ar1[-1]
			ar1.pop(-1)
			count += 1
		print(count, end=' ')
	j += 1


from sys import stdin, stdout

def input():
	return stdin.readline().strip()
MOD = 1000000007
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
ans = []
for i in range(n):
	x = a[:i]
	x.sort(reverse=True)
	tot = sum(x)
	count = 0
	for j in x:
		if tot <= m - a[i]:
			break
		tot -= j
		count += 1
	ans.append(count)
print(*ans)


(n, m) = [*map(int, input().split())]
list1 = [*map(int, input().split())]
list2 = []
for i in range(n):
	list2 = []
	for j in range(i):
		list2.append(list1[j])
	list2.sort()
	sum1 = 0
	counter1 = 0
	for k in range(i):
		sum1 += list2[k]
		if sum1 > m - list1[i]:
			counter1 = 1
			print(i - k, end=' ')
			break
	if counter1 == 0:
		print('0', end=' ')


(n, m) = list(map(int, input().split()))
s = list(map(int, input().split()))
for i in range(n):
	if sum(s[:i]) <= m - s[i]:
		print('0', end=' ')
	else:
		(tmp, sum1) = (sorted(s[:i]), sum(s[:i]))
		tmp.reverse()
		for j in range(i):
			sum1 -= tmp[j]
			if sum1 <= m - s[i]:
				print(j + 1, end=' ')
				break


(n, m) = map(int, input().split())
t = list(map(int, input().split()))
temp = []
total = 0
mostr = []
for i in range(0, n):
	if total + t[i] <= m:
		total += t[i]
		print(0, end=' ')
		mostr.append(t[i])
	else:
		mostr.sort()
		right = len(mostr) - 1
		count = 0
		result = total
		while result + t[i] > m and t[i] <= m:
			if len(mostr) > 0:
				count += 1
				result -= mostr[right]
				right -= 1
			else:
				break
		total += t[i]
		mostr.append(t[i])
		print(count, end=' ')


(n, m) = map(int, input().split())
iss = list(map(int, input().split()))
ii2 = []
for i in range(len(iss)):
	iss3 = iss[0:i]
	iss3.sort()
	iss3.reverse()
	k = 0
	ii = 0
	for j in range(i + 1):
		k += int(iss[j])
	if k <= m:
		ii2.append('0')
	else:
		while k > m:
			k -= int(iss3[0])
			iss3.pop(0)
			ii += 1
		ii2.append(str(ii))
print(' '.join(ii2))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list()
summ = 0
for i in range(len(a)):
	summ += a[i]
	b.append(summ)
for i in range(len(b)):
	c = a[:i]
	c.sort()
	if b[i] <= m:
		print(0, end=' ')
	else:
		diff = b[i] - m
		ctr = 0
		f = 0
		for j in range(len(c) - 1, -1, -1):
			if diff > 0:
				diff -= c[j]
				ctr += 1
			else:
				f = 1
				print(ctr, end=' ')
				break
		if f == 0:
			print(ctr, end=' ')


(n, m) = map(int, input().split())
s = list(map(int, input().split()))
record = []
needed = 0
remain = m
dp = [0 for i in range(n)]
dp[0] = 0
remain -= s[0]
record.append(s[0])
print('0', end=' ')
for i in range(1, n):
	needed = s[i]
	if needed <= remain:
		record.append(s[i])
		remain -= needed
		dp[i] = 0
		print(dp[i], end=' ')
	else:
		temp = record.copy()
		tempRem = remain
		temp.sort()
		c = 0
		while tempRem < needed:
			tempRem += temp.pop()
			c += 1
		record.append(s[i])
		remain -= needed
		dp[i] = c
		print(c, end=' ')
print('')


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
ans = []
arr = []
s = 0
for i in range(0, n):
	s += a[i]
	if s <= m:
		ans.append(0)
		arr.append(a[i])
	else:
		d = abs(s - m)
		s1 = 0
		count = 0
		arr.sort(reverse=True)
		for j in range(0, len(arr)):
			if s1 < d:
				s1 += arr[j]
				count += 1
			else:
				break
		arr.append(a[i])
		ans.append(count)
for k in range(0, n - 1):
	print(ans[k], end=' ')
print(ans[n - 1])


(n, M) = list(map(int, input().split()))
a = list(map(int, input().split()))
k = 0
pred = []
for i in range(n):
	k += a[i]
	if k <= M:
		print(0, end=' ')
	else:
		c = k
		l = -1
		r = 0
		while c > M:
			c -= pred[l]
			l -= 1
			r += 1
		print(r, end=' ')
	pred.append(a[i])
	pred.sort()


def main():
	(n, M) = input().split(' ')
	n = int(n)
	M = int(M)
	ts = input().split(' ')
	for i in range(n):
		ts[i] = int(ts[i])
	arr = []
	s = 0
	out = []
	for i in range(n):
		val = ts[i]
		s = s + val
		if s <= M:
			out.append(0)
			arr.append(ts[i])
			continue
		so = sorted(arr, reverse=True)
		dur = s
		for j in range(len(so)):
			dur = dur - so[j]
			if dur <= M:
				out.append(j + 1)
				break
		arr.append(ts[i])
	st = ''
	for val in out:
		st = st + str(val) + ' '
	print(st)
main()


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
print('0', end=' ')
d = [c[0]]
k = c[0]
for i in c[1:]:
	k += i
	if k > b:
		d.sort(reverse=True)
		g = 0
		ll = k
		for j in d:
			g += 1
			if ll - j <= b:
				print(g, end=' ')
				break
			else:
				ll -= j
	else:
		print('0', end=' ')
	d.append(i)


from itertools import accumulate
from sys import stdin

def main():
	(N, M) = map(int, input().split())
	T = list(map(int, input().split()))
	t = list(accumulate(T))
	ans = []
	for i in range(N):
		if t[i] <= M:
			ans.append(0)
		else:
			fail = 0
			for (j, t_) in enumerate(sorted(T[:i], reverse=1), start=1):
				fail += t_
				if t[i] - fail <= M:
					ans.append(j)
					break
	print(*ans)
input = lambda : stdin.readline()
main()


(n, M) = tuple(map(int, input().split()))
times = list(map(int, input().split()))
results = []
for i in range(n):
	before = times[:i]
	btime = sum(before)
	removed = 0
	while M - btime < times[i]:
		maximum = max(before)
		before.remove(maximum)
		removed += 1
		btime -= maximum
	results.append(removed)
print(*results, sep=' ')


from bisect import insort
(n, m) = map(int, input().split())
lis = list(map(int, input().split()))
pre = [lis[0]]
for i in lis[1:]:
	pre.append(pre[-1] + i)
srt = []
res = []
for i in range(n):
	if pre[i] <= m:
		res.append(0)
	else:
		c = 0
		x = pre[i] - m
		j = len(srt) - 1
		while x > 0:
			x -= srt[j]
			j -= 1
			c += 1
		res.append(c)
	insort(srt, lis[i])
for i in res:
	print(i, end=' ')
print()


(n, m) = map(int, input().split())
s = list(map(int, input().split()))
p = []
for i in range(len(s)):
	if sum(s[:i + 1]) <= m:
		p.append('0')
	else:
		res = 0
		g = s[:i]
		m1 = sum(s[:i + 1])
		while m1 > m:
			m1 -= g.pop(g.index(max(g)))
			res += 1
		p.append(str(res))
print(' '.join(p))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = []
sum1 = 0
ans = []
for i in range(n):
	sum1 = sum(a[:i + 1])
	cnt = 0
	while sum1 > m:
		cnt += 1
		sum1 -= b[-cnt]
	ans.append(cnt)
	b.append(a[i])
	b.sort()
print(*ans)


n = list(map(int, input().split()))
b = list(map(int, input().split()))
a = []
k = 0
ww = 0
for i in b:
	k = k + i
	a.append(k)
for i in range(n[0]):
	if a[i] <= n[1]:
		print('0', end=' ')
	else:
		c = b[0:i]
		c.sort()
		co = 0
		for hh in range(len(c) - 1, -1, -1):
			co = co + c[hh]
			if a[i] - co <= n[1]:
				print(len(c) - hh, end=' ')
				break


from heapq import heappush, heappop
t = 1
for test in range(t):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	heap = []
	ans = []
	cur_sum = 0
	for i in range(n):
		tmp_sum = cur_sum
		cur = 0
		popped = []
		while tmp_sum + arr[i] > m:
			val = heappop(heap)
			tmp_sum += val
			cur += 1
			popped.append(val)
		while popped:
			heappush(heap, popped.pop())
		cur_sum += arr[i]
		heappush(heap, -arr[i])
		ans.append(cur)
	print(*ans)


import heapq as h

def gre(lst, x):
	lst.sort(reverse=True)
	c = 0
	s = 0
	for i in range(len(lst)):
		s += lst[i]
		c += 1
		if s >= x:
			return c

def pro(arr, m):
	lst = [arr[0]]
	pre = [0] * len(arr)
	ans = [0] * len(arr)
	pre[0] = arr[0]
	for i in range(1, len(arr)):
		if pre[i - 1] + arr[i] <= m:
			pre[i] = pre[i - 1] + arr[i]
		else:
			req = m - arr[i]
			hav = pre[i - 1] - req
			ans[i] = gre(lst, hav)
			pre[i] = pre[i - 1] + arr[i]
		lst.append(arr[i])
	print(*ans)
(n, m) = list(map(int, input().split()))
arr = list(map(int, input().split()))
pro(arr, m)


(n, m) = input().split()
m = int(m)
l = list(map(int, input().split()))
s = l[0]
print(0, end=' ')
k = []
k.append(l[0])
for j in range(1, int(n)):
	s += l[j]
	if s <= m:
		print(0, end=' ')
	else:
		k.sort(reverse=True)
		c = 0
		ts = s
		e = 0
		while e < len(k) and ts > m:
			ts -= k[e]
			c += 1
			e += 1
		print(c, end=' ')
	k.append(l[j])


inputString = input().split(' ')
students = int(inputString[0])
totalTime = int(inputString[1])
studentTimes = input().split(' ')
studentTimes = [int(i) for i in studentTimes]
leaveArr = []
for i in range(0, len(studentTimes)):
	arrTillNow = studentTimes[:i + 1]
	lastElement = studentTimes[i]
	if sum(arrTillNow) <= totalTime:
		leaveArr.append(0)
	else:
		arrTillNow.pop()
		arrTillNow.sort()
		arrTillNow.insert(0, lastElement)
		count = 0
		while sum(arrTillNow) > totalTime:
			arrTillNow = arrTillNow[:len(arrTillNow) - 1]
			count += 1
		leaveArr.append(count)
print(' '.join([str(i) for i in leaveArr]).strip())


(n, M) = map(int, input().split())
t_s = list(map(int, input().split()))
res_s = [0] * n
for i in range(1, n):
	left = t_s[:i]
	sm = sum(left) + t_s[i]
	res = 0
	while sm > M:
		m = max(left)
		res += 1
		left.remove(m)
		sm -= m
	res_s[i] = res
print(' '.join(map(str, res_s)))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
ans = []
b = [a[0]]
for i in range(1, n):
	b.append(b[-1] + a[i])
for i in range(n):
	if b[i] > m:
		c = sorted(a[:i], reverse=True)
		k = 0
		r = b[i] - m
		while r > 0:
			r -= c[k]
			k += 1
		ans.append(k)
	else:
		ans.append(0)
print(*ans)


import heapq

def main():
	[n, limit] = list(map(int, input().split()))
	ar = list(map(int, input().split()))
	sumTillNow = 0
	i = 0
	setOfAr = list()
	m = {}
	while i < n:
		count = 0
		if sumTillNow + ar[i] > limit:
			temp = sumTillNow + ar[i]
			stack = list(setOfAr)
			while temp > limit:
				popped = stack.pop()
				temp = temp - popped
				count += 1
		if i == n - 1:
			print(count)
		else:
			print(count, end=' ')
		setOfAr.append(ar[i])
		setOfAr = sorted(setOfAr)
		sumTillNow += ar[i]
		i += 1
main()


def remove_student(n, m, l):
	for i in range(len(l)):
		if l[i] + sum(l[:i]) > m:
			nums = sorted(l[:i])
			total = l[i]
			for j in range(len(nums)):
				total += nums[j]
				if total > m:
					yield (len(nums) - j)
					break
		else:
			yield 0
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
print(' '.join(map(str, remove_student(n, m, l))))


aa = input()
bb = aa.split()
n = int(bb[0])
m = int(bb[1])
cc = input()
dd = cc.split()
e = []
for i in range(n):
	dd[i] = int(dd[i])
s = 0
tt = 0
e = []
for k in range(n):
	s = tt
	tt += dd[k]
	if dd[k] <= m - s:
		print(0, end=' ')
	else:
		c = 0
		fl = 0
		e.sort()
		for j in range(k - 1, -1, -1):
			if dd[k] <= m - s:
				print(c, end=' ')
				fl = 1
				break
			else:
				s -= e[j]
				c += 1
		if fl == 0:
			print(c, end=' ')
	e.append(dd[k])


from collections import Counter as C, defaultdict as D, deque as Q
from operator import itemgetter as I
from itertools import product as P
from bisect import bisect_left as BL, bisect_right as BR, insort as INSORT
from heapq import heappush as HPUSH, heappop as HPOP
from math import floor as MF, ceil as MC, gcd as MG, factorial as F, sqrt as SQRT, inf as INFINITY, log as LOG
from sys import stdin, stdout
INPUT = stdin.readline
PRINT = stdout.write
L = list
M = map

def player1():
	print('')

def player2():
	print('')

def isPrime(n):
	for i in range(2, MC(SQRT(n)) + 1):
		if n % i == 0:
			return False
	return True

def factors(x):
	ans = []
	for i in range(1, MC(SQRT(x)) + 1):
		if x % i == 0:
			ans.append(i)
			if x % (x // i) == 0:
				ans.append(x // i)
	return ans

def checkPath(source, destination, g):
	visited = [0] * 101
	q = Q()
	q.append(source)
	visited[source] = 1
	while q:
		node = q.popleft()
		if node == destination:
			return 1
		for v in g[node]:
			if not visited[v]:
				q.append(v)
				visited[v] = 1
	return 0

def main():
	(n, m) = M(int, INPUT().split())
	t = L(M(int, INPUT().split()))
	arr = []
	ans = [0] * n
	prefix = 0
	l = 0
	for i in range(n):
		if m - prefix < t[i]:
			s = 0
			count = 0
			j = l - 1
			while 1:
				if m - (prefix - s) >= t[i]:
					break
				s += arr[j]
				count += 1
				j -= 1
			ans[i] = count
		prefix += t[i]
		INSORT(arr, t[i])
		l += 1
	print(*ans)
main()


import bisect
(n, m) = list(map(int, input().split()))
t = list(map(int, input().split()))
ans = []
tt = []
for et in t:
	st = sum(tt) + et
	td = 0
	while st > m:
		td += 1
		st -= tt[-td]
	ans += [td]
	bisect.insort_left(tt, et)
print(*ans)


import sys
line = input().split()
[n, m] = [int(x) for x in line]
line = input().split()
a = [int(x) for x in line]
s = 0
x = []
for i in range(n):
	j = i - 1
	tmp = s
	count = 0
	while j >= 0 and tmp > m - a[i]:
		tmp -= x[j]
		j -= 1
		count += 1
	sys.stdout.write(str(count) + ' ')
	x.append(a[i])
	x.sort()
	s += a[i]


(n, m) = input().split()
m = int(m)
t = [int(x) for x in input().split()]
l = []
for i in t:
	count = 0
	n = l[:]
	if sum(l) + i <= m:
		print(0, end=' ')
	else:
		l.sort()
		while sum(l) + i > m:
			l.remove(l[-1])
			count += 1
		print(count, end=' ')
	n.append(i)
	l = n


import sys, math

def read_int():
	return int(sys.stdin.readline().strip())

def read_int_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def read_string():
	return sys.stdin.readline().strip()

def read_string_list(delim=' '):
	return sys.stdin.readline().strip().split(delim)

def print_list(l):
	print(' '.join(map(str, l)))
(n, m) = read_int_list()
times = read_int_list()
for i in range(n):
	if sum(times[:i]) + times[i] > m:
		sorted_times = sorted(times[:i], reverse=True)
		for j in range(i):
			if sum(times[:i]) + times[i] - sum(sorted_times[:j + 1]) <= m:
				print(j + 1, end=' ')
				break
	else:
		print('0', end=' ')
print()


a = [int(i) for i in input().split()]
n = a[0]
M = a[1]
x = [int(i) for i in input().split()]
pref = [0 for i in x]
pref[0] = x[0]
arr = [i for i in x]
for i in range(1, n):
	pref[i] = pref[i - 1] + x[i]
for i in range(n):
	ans = pref[i]
	if ans <= M:
		print(0, end=' ')
	else:
		arr = sorted(x[:i], reverse=True)
		k = 0
		while ans > M:
			ans -= arr[k]
			k += 1
		print(k, end=' ')


(nStudents, duration) = map(int, input().split())
t = list(map(int, input().split()))
ret = []
before = 0
for i in range(nStudents):
	if duration - before >= t[i]:
		ret.append(0)
	else:
		studentsBefore = sorted(t[:i])
		tempBefore = before
		remove = i - 1
		while duration - tempBefore < t[i]:
			tempBefore -= studentsBefore[remove]
			remove -= 1
		ret.append(i - remove - 1)
	before += t[i]
print(*ret)


def sumf(l):
	s = 0
	for i in range(0, len(l)):
		s += l[i]
	return s

def f(list1, i, m):
	count = 0
	sum = 0
	list2 = []
	for x in range(0, i + 1):
		sum = sum + list1[x]
		list2.append(list1[x])
	if sum <= m:
		print(0, end=' ')
	else:
		list2.pop(-1)
		list2.sort()
		while sumf(list2) > m - list1[i]:
			list2.pop(-1)
			count += 1
		print(count, end=' ')
(n, m) = map(int, input().split())
l = input().split()
l = list(map(int, l))
for i in range(0, n):
	f(l, i, m)


(n, m) = map(int, input().split())
ar = list(map(int, input().split()))
d = []
for i in range(n):
	summ = 0
	for j in range(i + 1):
		summ += ar[j]
	if summ <= m:
		d.append(0)
	else:
		cnt = 0
		arr = ar[:i]
		arr.sort()
		t = len(arr) - 1
		summ = sum(arr) + ar[j]
		while summ > m:
			summ -= arr[t]
			t -= 1
			cnt += 1
		d.append(cnt)
print(*d)


(n, s) = [int(x) for x in input().split(' ')]
arr = [int(x) for x in input().split(' ')]
arr2 = [arr[0]]
for x in range(1, n):
	arr2.append(arr2[-1] + arr[x])
ans = [0]
for i in range(1, n):
	if arr2[i] <= s:
		ans.append(0)
	else:
		temp = sorted(arr[:i])
		temp2 = [temp[0]]
		for _ in range(1, len(temp)):
			temp2.append(temp2[-1] + temp[_])
		x = i - 1
		c = 0
		while x >= 0 and temp2[x] + arr[i] > s:
			c += 1
			x -= 1
		ans.append(c)
for item in ans:
	print(item, end=' ')


(n, m) = map(int, input().split())
A = [int(x) for x in input().split()]
print(0, end=' ')
i = 1
while i < n:
	p = 0
	k = m - A[i]
	cnt = 0
	B = sorted(A[:i])
	while p < i and k - B[p] >= 0:
		k -= B[p]
		p += 1
	print(i - p, end=' ')
	i += 1


import queue
from heapq import heappush as insert, heappop as extract_maximum
(n, M) = map(int, input().split())
data = list(map(int, input().split()))
true_sum = 0
true_tempo = []
for i in range(len(data)):
	tempo = true_tempo.copy()
	true_sum += data[i]
	sum = true_sum
	cnt = 0
	while sum > M:
		sum -= abs(extract_maximum(tempo))
		cnt += 1
	print(cnt, end=' ')
	insert(true_tempo, -1 * data[i])


(n, M) = map(int, input().split())
t = [int(i) for i in input().split()]
for i in range(n):
	s = t[i]
	finish_t = sum(t[:i + 1])
	if finish_t > M:
		prev_t = t[:i]
		prev_t.sort()
		left_s = 0
		while finish_t > M:
			finish_t -= prev_t.pop(len(prev_t) - 1)
			left_s += 1
		print(left_s, end=' ')
	else:
		print(0, end=' ')


from heapq import *
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
ans = []
h = []
for i in a:
	l = h.copy()
	heappush(h, -i)
	c = 0
	while -sum(l) + i > m:
		heappop(l)
		c += 1
	ans.append(c)
print(*ans)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
	if sum(a[:i + 1]) <= m:
		print(0, end=' ')
	else:
		ans = 0
		dop = a[:i]
		tc = sum(a[:i + 1])
		while tc > m:
			tc -= dop.pop(dop.index(max(dop)))
			ans += 1
		print(ans, end=' ')


import bisect
(n, m) = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
s = [t[0]]
ans = '0'
k = t[0]
for i in t[1:]:
	k += i
	if k <= m:
		ans = ans + ' ' + '0'
	else:
		j = 1
		h = 0
		while h < k - m:
			h += s[-j]
			j += 1
		ans = ans + ' ' + str(j - 1)
	bisect.insort(s, i)
print(ans)


(n, M) = map(int, input().split())
t = [int(x) for x in input().split()]
for i in range(n):
	na = t[:i]
	na.sort(reverse=True)
	c = 0
	s = sum(na)
	for j in na:
		if s + t[i] <= M:
			break
		elif s - j + t[i] <= M:
			c = c + 1
			break
		else:
			c = c + 1
			s = s - j
	print(c, end=' ')


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
su = 0
ans = []
for i in range(n):
	su += l[i]
	if su <= m:
		ans.append(0)
	else:
		r = l[0:i]
		r.sort(reverse=True)
		temp = 0
		for j in range(len(r)):
			temp += r[j]
			if su - temp <= m:
				ans.append(j + 1)
				break
print(*ans)


(n, m) = map(int, input().split())
n = list(map(int, input().split()))
b = []
c = []
for i in range(len(n)):
	t = 0
	e = 0
	if i > 0:
		b.append(n[i - 1])
		b.sort(reverse=True)
	for a in range(len(n) - (len(n) - i)):
		t += n[a]
	t += n[i]
	if t <= m:
		c.append(0)
	else:
		while t > m:
			t -= b[e]
			e += 1
		c.append(e)
print(*c)


from sys import stdin
(n, m) = map(int, stdin.readline().strip().split())
s = list(map(int, stdin.readline().strip().split()))
ans = [0 for i in range(n)]
sm = [0 for i in range(n)]
sm1 = [0 for i in range(n)]
for i in range(n):
	if i == 0:
		sm[i] = s[i]
	else:
		sm[i] = sm[i - 1] + s[i]
for i in range(n - 1, -1, -1):
	if i == n - 1:
		sm1[i] = s[i]
	else:
		sm1[i] = sm1[i + 1] + s[i]
for i in range(n):
	if sm[i] <= m:
		continue
	x = sm[i]
	s2 = s[0:i]
	s2.sort()
	r = 0
	while x > m:
		x -= s2[-1]
		s2.pop()
		r += 1
	ans[i] = r
print(*ans)


(n, m) = map(int, input().split())
(tot_sum, curr_sum, d) = (0, 0, {})
arr = list(map(int, input().split()))
for x in arr:
	tot_sum += x
	curr_sum += x
	curr_res = 0
	for it in sorted(d.keys(), reverse=True):
		if curr_sum <= m:
			break
		take = min(d[it], (curr_sum - m + it - 1) // it)
		curr_sum -= take * it
		curr_res += take
	d[x] = 1 if x not in d else d[x] + 1
	curr_sum = tot_sum
	print(curr_res, end=' ')


(n, m) = tuple(map(int, input().split()))
a = list(map(int, input().split()))
r = [0 for _ in range(n)]
b = [a[0]]
for i in range(1, n):
	left = m - a[i]
	(s, j) = (0, 0)
	for jr in range(0, i):
		if s + b[jr] > left:
			break
		s += b[jr]
		j += 1
	r[i] = i - j
	b.append(a[i])
	b.sort()
print(*r, sep=' ')


import sys
from heapq import heappop, heappush, heapify
heap = []
heapify(heap)
for _ in range(1):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	ans = [0] * n
	(a, b) = (0, 0)
	for i in range(n):
		temp = []
		while a + l[i] > k:
			temp.append(heappop(heap))
			a += temp[-1]
		ans[i] = len(temp) + b
		while temp:
			a -= temp[-1]
			heappush(heap, temp.pop())
		a += l[i]
		heappush(heap, -l[i])
		if a > k:
			a += heappop(heap)
			b += 1
	print(*ans)


import heapq
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
cur = 0
ans = []
val = []
for i in range(n):
	cur += l[i]
	if cur <= m:
		ans.append(0)
		val.append(l[i])
	else:
		count = 0
		extra = []
		heapq._heapify_max(val)
		c = cur
		while c > m:
			x = heapq._heappop_max(val)
			extra.append(x)
			c -= x
			count += 1
		val.append(l[i])
		val += extra
		ans.append(count)
print(*ans)


n = []
t = []
n = list(map(int, input().split()))
t = list(map(int, input().split()))
result = []
for i in range(len(t)):
	number = int(0)
	x = t[0:i + 1]
	re = int(0)
	for j in range(i + 1):
		re += x[j]
	x.pop(i)
	while re > n[1]:
		re -= max(x)
		x.pop(x.index(max(x)))
		number += 1
	result.append(number)
print(' '.join((str(x) for x in result)))


import sys
from collections import Counter
from heapq import heappush, heappop
(n, m) = map(int, sys.stdin.readline().split())
times = list(map(int, sys.stdin.readline().split()))
remainings = []
removemes = []
time_remaining = 0
len_removed = 0
res = []
for t in times:
	while time_remaining + t > m:
		tmp = -1 * heappop(remainings)
		time_remaining -= tmp
		len_removed += 1
		heappush(removemes, tmp)
	res.append(str(len_removed))
	if bool(removemes) and t > removemes[0]:
		heappush(removemes, t)
		len_removed += 1
		while bool(removemes) and t > removemes[0]:
			tmp = heappop(removemes)
			len_removed -= 1
			heappush(remainings, -1 * tmp)
			time_remaining += tmp
	else:
		heappush(remainings, -1 * t)
		time_remaining += t
print(' '.join(res))


(n, maxi) = list(map(int, input().split()))
List = list(map(int, input().split()))
List2 = ['0']
for i in range(1, n):
	c = List[:]
	count = 0
	while sum(c[:i]) > maxi - c[i]:
		index = c.index(max(c[:i]))
		c[index] = 0
		count += 1
	List2.append(str(count))
print(' '.join(List2))


import bisect
(n, M) = list(map(int, input().split()))
nums = list(map(int, input().split()))
sorted_list = []
tm = 0
for i in range(n):
	ans = 0
	tm += nums[i]
	if tm > M:
		extra = tm - M
		red = 0
		while red < extra:
			red += sorted_list[i - 1 - ans]
			ans += 1
	bisect.insort(sorted_list, nums[i])
	print(ans, end=' ')


from bisect import *
(N, M) = input().split()
nums = [int(x) for x in input().split()]
pre = [0]
for n in nums:
	pre.append(pre[-1] + n)
pre = pre[1:]
sor = []
ans = ''
for i in range(len(pre)):
	if pre[i] > int(M):
		cnt = 0
		sm = 0
		for j in range(len(sor) - 1, -1, -1):
			sm += sor[j]
			cnt += 1
			if sm >= pre[i] - int(M):
				break
		ans += str(cnt) + ' '
	else:
		ans += '0 '
	insort(sor, nums[i])
print(ans[:len(ans) - 1])


f = []
f.append(0)
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(1, n):
	s = []
	for j in range(i):
		s.append(a[j])
	k = m - a[i]
	c = 0
	s.sort()
	for ele in s:
		if ele <= k:
			k -= ele
			c += 1
	d = i - c
	f.append(d)
for ele in f:
	print(ele, end=' ')


(n, m) = map(int, input().split())
data = list(map(int, input().split()))
a = []
for i in data:
	count = 0
	b = list(a)
	while sum(b) + i > m:
		mmm = max(b)
		b.remove(mmm)
		count += 1
	a.append(i)
	print(count, end=' ')


def solve(s, t):
	pass
(n, m) = map(int, input().split())
Time = list(map(int, input().split()))
Sum = [0] * n
Sum[0] = Time[0]
for i in range(1, n):
	Sum[i] += Sum[i - 1] + Time[i]
for i in range(n):
	if Sum[i] <= m:
		print(0, end=' ')
	else:
		LL = Time[:i]
		LL.sort()
		s = Sum[i]
		while m < s:
			p = LL.pop()
			s -= p
		print(i - len(LL), end=' ')


gi = lambda : list(map(int, input().strip().split()))
(n, m) = gi()
l = gi()
print(0, end=' ')
a = [l[0]]
for k in range(1, n):
	a.sort(reverse=True)
	tmp = m - sum(a) - l[k]
	i = 0
	while tmp < 0:
		tmp += a[i]
		i += 1
	print(i, end=' ')
	a.append(l[k])


def fail_student(n, m, l):
	(d, k, s, t, j) = ([], [], 0, 0, 0)
	for i in l:
		s += i
		t = s
		j = 0
		while t > m:
			t -= k[j]
			j += 1
		k.append(i)
		k.sort(reverse=True)
		d.append(j)
	print(*d)
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
fail_student(n, m, l)


(n, M) = map(int, input().split())
l = list(map(int, input().split()))
L = []
s = 0
for i in range(n):
	ans = 0
	r = s + l[i]
	k = len(L) - 1
	while r > M:
		r -= L[k]
		k -= 1
		ans += 1
	print(ans, end=' ')
	L.append(l[i])
	L.sort()
	s += l[i]


(n, m) = map(int, input().split())
t = list(map(int, input().split()))
print(0, end=' ')
for i in range(1, len(t)):
	temp = sorted(t[:i])
	time = m - t[i]
	ptr = 0
	while ptr < i and time - temp[ptr] >= 0:
		time -= temp[ptr]
		ptr += 1
	print(i - ptr, end=' ')
print()


import sys
input = sys.stdin.readline
from collections import defaultdict as dc
from collections import Counter
from bisect import bisect_right, bisect_left
import math
from heapq import heapify, heappop, heappush
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
s = [i for i in l]
x = 0
f = 0
for i in range(1, n):
	s[i] += s[i - 1]
	if s[i] > m and f == 0:
		x = i
		f = 1
p = [0] * n
if f == 0:
	print(*p)
else:
	for i in range(x, n):
		if s[i - 1] > m:
			c = abs(s[i - 1] - m)
		else:
			c = s[i - 1] - m
		c += l[i]
		t = 0
		q = 0
		y = sorted(l[:i], reverse=True)
		for j in y:
			if q >= c:
				break
			q += j
			t += 1
		p[i] = t
	print(*p)


(n, M) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
ans = []
for i in range(n):
	s = M - a[i]
	b = a[:i]
	t = 0
	for j in range(i):
		if s - min(b) >= 0:
			s -= min(b)
			b.pop(b.index(min(b)))
		else:
			t += 1
			continue
	ans.append(str(t))
print(' '.join(ans))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
ans = []
ma = 0
tc = [0] * (max(a) + 1)
for (i, k) in enumerate(a):
	tcm = 0
	dop = 0
	ma = m - k
	for j in range(1, len(tc)):
		if ma < tcm + tc[j] * j:
			dop += (ma - tcm) // j
			break
		else:
			tcm += tc[j] * j
			dop += tc[j]
	ans.append(i - dop)
	tc[k] += 1
print(*ans)


from itertools import accumulate
(n, M) = map(int, input().split())
t = list(map(int, input().split()))
res = [0] * n
for i in range(n):
	tt = list(accumulate(sorted(t[:i + 1])))
	if tt[-1] > M:
		ttt = list(accumulate(sorted(t[:i], reverse=True)))
		k = 0
		while k < len(ttt):
			if tt[-1] - ttt[k] > M:
				k += 1
			else:
				break
		res[i] = k + 1
print(*res)


import bisect
(n, M) = map(int, input().split(' '))
t = list(map(int, input().split(' ')))

def find_ans(time):
	tolerate = M - time
	summa = 0
	passed = 0
	for x in prev:
		next_summa = summa + x
		if next_summa <= tolerate:
			summa = next_summa
			passed += 1
		else:
			break
	bisect.insort_left(prev, time)
	return str(len(prev) - passed - 1)
prev = []
ans = [find_ans(time) for time in t]
print(' '.join(ans))


import heapq
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
result = []
for i in range(n):
	e = a[:i]
	heapq._heapify_max(e)
	count = 0
	while sum(e) + a[i] > m:
		heapq._heappop_max(e)
		count += 1
	result.append(count)
print(' '.join(map(str, result)))


import math
(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
prefix = [0] * n
count = [0] * 101
for i in range(101):
	count[i] = [0] * 200001
for i in range(n):
	prefix[i] = prefix[i - 1] + arr[i]
	for j in range(1, 101):
		count[j][i] = count[j][i - 1]
		if j == arr[i]:
			count[j][i] += 1
for i in range(n):
	if prefix[i] <= m:
		print(0, end=' ')
	else:
		ct = 0
		sm = prefix[i]
		for j in range(100, 0, -1):
			if sm - count[j][i - 1] * j > m:
				ct += count[j][i - 1]
				sm -= count[j][i - 1] * j
			else:
				ct += math.ceil((sm - m) / j)
				print(ct, end=' ')
				break


import math
import bisect
import heapq
from collections import defaultdict

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, x, y) = egcd(b % a, a)
		return (g, y - b // a * x, x)

def mulinv(b, n):
	(g, x, _) = egcd(b, n)
	if g == 1:
		return x % n

def isprime(n):
	for d in range(2, int(math.sqrt(n)) + 1):
		if n % d == 0:
			return False
	return True

def argsort(ls):
	return sorted(range(len(ls)), key=ls.__getitem__)

def f(p=0):
	if p == 1:
		return map(int, input().split())
	elif p == 2:
		return list(map(int, input().split()))
	elif p == 3:
		return list(input())
	else:
		return int(input())

class DisjointSet:

	def __init__(self, n):
		self.parent = [i for i in range(1, n + 1)]
		self.rank = [0] * (n + 1)

	def find_set(self, x):
		if self.parent[x] == x:
			return x
		else:
			self.parent[x] = self.find_set(self.parent[x])
			return self.parent[x]

	def union(self, x, y):
		set_x = self.find_set(x)
		set_y = self.find_set(y)
		if set_x != set_y:
			if self.rank[x]:
				pass

def graph(n, m, edg=False):
	edges = []
	visited = [0] * n
	g = [list() for _ in range(n + 1)]
	for i in range(m):
		(u, v) = f(1)
		g[u].append(v)
		g[v].append(u)
		if edg:
			edges.append((u, v))
	if edg:
		return (g, visited, edg)
	else:
		return (g, visited)

def bfs(g, visited):
	queue = [1]
	visited[1] = 1
	for u in queue:
		for v in g[u]:
			if visited[v] == 0:
				queue.append(v)
			visited[v] = 1

def dfs(u, g, visited):
	visited[u] = 1
	for v in g[u]:
		if visited[v] == 0:
			dfs(v, g, visited)
(n, t) = f(1)
cl = f(2)
pl = []
count = 0
sm = 0
res = []
for i in range(n):
	sm += cl[i]
	k = t - sm
	j = count - 1
	while j > -1 and k < 0:
		k += pl[j]
		j -= 1
	if k < 0:
		res.append(count)
	else:
		res.append(count - j - 1)
	bisect.insort(pl, cl[i])
	count += 1
print(*res)


from bisect import bisect_right as B
(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(n):
	b = []
	for j in range(i):
		b.append(a[j])
	b.sort()
	for j in range(1, i):
		b[j] += b[j - 1]
	x = m - a[i]
	x = B(b, x)
	print(len(b) - x, end=' ')
print()


from sys import stdin, stdout
import math
import collections
(n, m) = list(map(int, stdin.readline().split()))
arr = list(map(int, stdin.readline().split()))
aux = []
for i in range(len(arr)):
	aux.sort()
	count = 0
	j = len(aux)
	while sum(aux[:j]) + arr[i] > m:
		j -= 1
		count += 1
	print(count, end=' ')
	aux.append(arr[i])


import sys
(n, M) = list(map(int, sys.stdin.readline().strip().split()))
t = list(map(int, sys.stdin.readline().strip().split()))
L = [0] * (n + 1)
x = ''
for i in range(1, n + 1):
	ans = 0
	for j in range(0, i):
		if L[j] <= M - t[i - 1]:
			ans = i - 1 - j
	L[i] = L[i - 1] + t[i - 1]
	for j in range(1, i):
		L[i - j] = min([L[i - j], L[i - j - 1] + t[i - 1]])
	x = x + str(ans) + ' '
print(x)


from heapq import heappush, heappop
(n, m) = tuple(map(int, input().rstrip().split()))
t = list(map(int, input().rstrip().split()))
times = []
total_time = 0
results = []
for i in range(0, n):
	total_time += t[i]
	skipped_students = 0
	if total_time <= m:
		heappush(times, -t[i])
		results.append(skipped_students)
	else:
		curr_total_time = total_time
		skipped_times = []
		while curr_total_time > m:
			curr_time = -heappop(times)
			skipped_times.append(curr_time)
			curr_total_time -= curr_time
			skipped_students += 1
		for tim in skipped_times:
			heappush(times, -tim)
		results.append(skipped_students)
		heappush(times, -t[i])
print(' '.join((str(x) for x in results)))


order = []

def insert(val):
	i = len(order) - 1
	while i >= 0:
		if order[i] <= val:
			break
		i -= 1
	order.insert(i + 1, val)
(N, M) = list(map(int, input().split()))
t = list(map(int, input().split()))
ans = [0] * N
time = 0
for i in range(N):
	time += t[i]
	curTime = time
	if time > M:
		j = i - 1
		while curTime > M:
			curTime -= order[j]
			j -= 1
			ans[i] += 1
	insert(t[i])
print(' '.join(map(str, ans)))


from math import *
from collections import *
from itertools import *
from functools import *
from random import *

def getl(t=int):
	return [t(x) for x in input().split()]

def get(t=int):
	return t(input())
alphabet = [chr(x) for x in range(ord('a'), ord('z') + 1)]
alnum = lambda x: ord(x) - ord('a')

def main():
	(n, m) = getl()
	l = getl()
	for i in range(n):
		l1 = sorted(l[:i], reverse=True)
		ti = l[i]
		s1 = sum(l1)
		ans = 0
		for c in l1:
			if s1 + ti > m:
				s1 -= c
				ans += 1
		print(ans, end=' ')
main()


import heapq
(n, M) = map(int, input().split())
list = [int(x) for x in input().split()]
heap = []
heapq.heapify(heap)
sum = 0
for i in range(n):
	buff = []
	count = 0
	while sum + list[i] > M:
		temp = heapq.heappop(heap)
		sum += temp
		buff.append(-temp)
		count += 1
	heapq.heappush(heap, -list[i])
	sum += list[i]
	while len(buff) != 0:
		temp = buff.pop()
		sum += temp
		heapq.heappush(heap, -temp)
	print(count, end=' ')


(a, b) = map(int, input().split())
s = [int(x) for x in input().split()]
for i in range(a):
	sc = sorted(s[:i])
	ans = 0
	thistm = sum(sc)
	while thistm + s[i] > b:
		ans += 1
		thistm -= sc.pop()
	print(ans, end=' ')


import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline

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

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

def read_float():
	return float(input())

def read_float_n():
	return list(map(float, input().split()))

def read_str():
	return input().strip()

def read_str_n():
	return list(map(str, input().split()))

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

def slv(N, M, S):
	ans = []
	m = 0
	c = [0] * (max(S) + 1)
	for (i, s) in enumerate(S):
		sm = 0
		sp = 0
		m = M - s
		for j in range(1, len(c)):
			if m < sm + c[j] * j:
				sp += (m - sm) // j
				break
			else:
				sm += c[j] * j
				sp += c[j]
		ans.append(i - sp)
		c[s] += 1
	return ' '.join(map(str, ans))

def main():
	(N, M) = read_int_n()
	S = read_int_n()
	print(slv(N, M, S))
main()


(n, m) = list(map(int, input().split()))
times = list(map(int, input().split()))
ans = []
for i in range(n):
	skips = 0
	xtimes = sorted(times[:i])
	ttime = sum(xtimes) + times[i]
	while ttime > m:
		skips += 1
		ttime -= xtimes.pop()
	ans.append(skips)
print(' '.join([str(a) for a in ans]))


(n, m) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
answer = [0]
students = [a[0]]
for i in range(1, n):
	students.sort(reverse=True)
	time = m - sum(students)
	counter = 0
	for item in students:
		if time >= a[i]:
			answer.append(counter)
			break
		else:
			counter += 1
			time += item
	else:
		answer.append(counter)
	students.append(a[i])
print(*answer)


(n, M) = map(int, input().split())
arr = input().split()
l = []
sum_list = []
s = 0
for i in range(n):
	s += int(arr[i])
	sum_list.append(s)
	l.append(int(arr[i]))
if l[0] <= M:
	print('0', end=' ')
for i in range(1, n):
	if l[i] + sum_list[i - 1] <= M:
		print('0', end=' ')
	else:
		duplicate_l = l.copy()
		ctr = 0
		s = l[i] + sum_list[i - 1]
		while s > M:
			s -= max(duplicate_l[0:i])
			duplicate_l[duplicate_l.index(max(duplicate_l[0:i]))] = 0
			ctr += 1
		print(ctr, end=' ')


import bisect
(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
s = 0
li = []
for i in range(n):
	s += arr[i]
	if s > m:
		count = 0
		k = s
		index = i - 1
		while k > m:
			k -= li[index]
			count += 1
			index -= 1
		print(count, end=' ')
	else:
		print(0, end=' ')
	x = bisect.bisect(li, arr[i])
	li.insert(x, arr[i])


import heapq
(n, M) = map(int, input().split())
M = -M
ti = list(map(int, input().split()))
ti = map(lambda i: -1 * i, ti)
li = []
ans = []
heapq.heapify(li)
summ = 0
for i in ti:
	summ += i
	ab = summ
	if summ >= M:
		heapq.heappush(li, i)
		ans.append(0)
	if summ < M:
		count = 0
		a = li.copy()
		while summ < M:
			summ -= a[0]
			count += 1
			heapq.heappop(a)
		heapq.heappush(li, i)
		summ = ab
		ans.append(count)
print(*ans)


x_ = input().split()
x = [int(d) for d in x_]
y_ = input().split()
y = [int(d) for d in y_]
total_time = x[1]
ans = []
for i in range(x[0]):
	if sum(y[:i + 1]) <= total_time:
		ans.append(0)
	elif sum(y[:i + 1]) > total_time:
		u = y[:i]
		u.sort(reverse=True)
		j = 0
		k = 0
		while sum(y[:i + 1]) - sum(u[:j]) > total_time:
			j = j + 1
			k = k + 1
		ans.append(k)
print(*ans)


import atexit
import io
import sys
import bisect
_I_B = sys.stdin.read().splitlines()
input = iter(_I_B).__next__
_O_B = io.StringIO()
sys.stdout = _O_B

@atexit.register
def write():
	sys.__stdout__.write(_O_B.getvalue())

def main():
	(n, m) = map(int, input().split())
	t = list(map(int, input().split()))
	s = []
	su = 0
	for i in t:
		su += i
		if su > m:
			f = 0
			tsu = su
			idx = len(s) - 1
			while tsu > m:
				f += 1
				tsu -= s[idx]
				idx -= 1
			print(f, end=' ')
		else:
			print(0, end=' ')
		bisect.insort(s, i)
	print()
main()


(n, M) = map(int, input().split())
L = list(map(int, input().split()))
s = 0
for i in range(0, n):
	br = 0
	s = s + L[i]
	sc = s
	Lc = L[:]
	if s <= M:
		print(br, end=' ')
	else:
		b2 = 0
		while s > M:
			s = s - max(L[0:i - b2])
			L.remove(max(L[0:i - b2]))
			br += 1
			b2 += 1
		print(br, end=' ')
	s = sc
	L = Lc[:]


(n, M) = map(int, input().split())
l = list(map(int, input().split()))
r = [0]
for i in range(1, len(l)):
	t = M
	l[:i] = sorted(l[:i])
	t -= l[i]
	sum = 0
	for j in range(i):
		t -= l[j]
		if t >= 0:
			sum += 1
		else:
			break
	r.append(i - sum)
for i in r:
	print(i, end=' ')


import sys
from os import path
if path.exists('input.txt') and path.exists('output.txt'):
	sys.stdout = open('output.txt', 'w')
	sys.stdin = open('input.txt', 'r')

def main():
	(n, m) = (int(i) for i in input().split())
	times = [int(i) for i in input().split()]
	for i in range(n):
		sliced = times[:i]
		sm = sum(sliced) + times[i]
		if sm <= m:
			print(0, end=' ')
		else:
			ans = 0
			sliced.sort(reverse=True)
			for sl in sliced:
				sm -= sl
				ans += 1
				if sm <= m:
					print(ans, end=' ')
					break
main()


(a, b) = list(map(int, input().split()))
l = list(map(int, input().split()))
ans = [0]
for i in range(len(l)):
	ans.append(l[i] + ans[-1])
i = 0
n_ans = []
ans.pop(0)
while i < a:
	if ans[i] <= b:
		n_ans.append(0)
	else:
		l[0:i] = sorted(l[0:i])
		tar = ans[i]
		c = 0
		while tar > b:
			c += 1
			tar -= l[i - c]
		n_ans.append(c)
	i += 1
print(*n_ans)


(n, M) = list(map(int, input().strip().split()))
t = list(map(int, input().strip().split()))
res = []
for i in range(n):
	l = t.copy()
	l = l[:i]
	l.sort()
	l = l[::-1]
	j = 0
	while M - t[i] - sum(l[j:]) < 0:
		j += 1
	res.append(str(j))
print(' '.join(res))


(n, m) = list(map(int, input().split()))
t = list(map(int, input().split()))
for i in range(n):
	a = sorted(t[:i])
	s = sum(a) + t[i]
	c = 0
	while s > m:
		s -= a.pop(-1)
		c += 1
	print(c, end=' ')


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
ans = []
sumi = 0
for i in range(n):
	sumi = sum(a[:i + 1])
	co = 0
	temp = a[:i]
	while sumi > m:
		co += 1
		sumi = sumi - max(temp)
		temp.remove(max(temp))
	ans.append(co)
print(*ans)


(n, m) = (int(x) for x in input().split())
tests = [int(x) for x in input().split()]
su = 0
output = []
for i in range(n):
	su += tests[i]
	if su <= m:
		output.append(0)
	else:
		newi = i
		counter = 0
		newsu = su
		tests1 = tests[:i]
		tests1.sort()
		while newsu > m:
			newi -= 1
			newsu -= tests1[newi]
			counter += 1
		output.append(counter)
out = ''
for i in output:
	out += str(i) + ' '
out = out[:-1]
print(out)


from itertools import *
from math import *
from collections import *
from heapq import *
from bisect import bisect_left, bisect_right
from copy import deepcopy
inf = float('inf')
mod = 10 ** 9 + 7
from functools import reduce
import sys
sys.setrecursionlimit(10 ** 7)
(n, M) = map(int, input().split())
t = list(map(int, input().split()))
h = []
(sum, a) = (0, 0)
ans = []
for i in range(n):
	if sum - t[i] >= -M:
		ans.append(0)
		heappush(h, -t[i])
		sum -= t[i]
	else:
		h1 = deepcopy(h)
		heapify(h1)
		a = 0
		sum1 = sum
		while sum1 - t[i] < -M:
			b = heappop(h1)
			sum1 -= b
			a += 1
		ans.append(a)
		heappush(h, -t[i])
		sum -= t[i]
print(*ans, sep=' ')


(n, m) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
ans = [0] * n
pre = [0] * n
pre[0] = a[0]
for i in range(1, n):
	pre[i] = pre[i - 1] + a[i]
aux = []
aux.append(a[0])
for i in range(1, n):
	if pre[i] > m:
		temp = pre[i]
		count = 0
		aux.sort()
		j = len(aux) - 1
		while temp > m:
			temp = temp - aux[j]
			j = j - 1
			count = count + 1
		ans[i] = count
	aux.append(a[i])
for i in ans:
	print(i, end=' ')


inp = list(map(int, input().split()))
t = inp[1]
inp = list(map(int, input().split()))
l = []
for i in range(1, len(inp) + 1):
	l.append(sum(inp[:i]))
for i in range(len(l)):
	if l[i] < t:
		print(0, end=' ')
	else:
		k = l[i] - t
		j = inp[:i]
		j.sort(reverse=True)
		sumi = 0
		count = 0
		p = 0
		while sumi < k:
			sumi = sumi + j[count]
			count += 1
		print(count, end=' ')


def fail_student(n, m, l):
	d = []
	for i in range(n):
		k = sorted(l[:i])
		s = sum(k)
		j = 0
		while s + l[i] > m:
			s -= k.pop()
			j += 1
		d.append(j)
	return d
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
print(*fail_student(n, m, l))


from copy import copy
(n, m) = map(int, input().split())
T = list(map(int, input().split()))
Z = copy(T)
for i in range(1, n):
	Z[i] += Z[i - 1]
for i in range(n):
	if Z[i] <= m:
		print(0, end=' ')
	else:
		A = T[:i]
		A.sort()
		s = 0
		for j in range(len(A)):
			s += A[j]
			if s > m - T[i]:
				print(len(A) - j, end=' ')
				break


(N, M) = map(int, input().split())
A = [int(a) for a in input().split()]
ANS = []
X = []
t = 0
for i in range(N):
	tt = t
	j = 0
	while A[i] > M - tt:
		tt -= X[j]
		j += 1
	ANS.append(j)
	X = sorted(X + [A[i]])[::-1]
	t += A[i]
print(*ANS)


(m, M) = map(int, input().split())
arr = list(map(int, input().split()))
res = [0] * m
sm = arr[0]
cnt = 0
curr = [arr[0]]
for i in range(1, m):
	temp = M - sm
	if arr[i] <= M - sm:
		sm += arr[i]
		curr.append(arr[i])
		curr.sort(reverse=True)
	else:
		k = 0
		cnt = 0
		sm2 = sm
		while arr[i] > M - sm2:
			sm2 -= curr[k]
			cnt += 1
			k += 1
		sm += arr[i]
		curr.append(arr[i])
		curr.sort(reverse=True)
	res[i] = cnt
print(*res)


def getN():
	return int(input())

def getList():
	return list(map(int, input().split()))
(n, m) = getList()
nums = getList()

def solve(nums, m, i):
	tgt = nums[i]
	queue = nums[:i]
	queue.sort()
	for (idx, q) in enumerate(queue):
		tgt += q
		if tgt > m:
			return i - idx
	return 0
answers = []
for i in range(n):
	answers.append(solve(nums, m, i))
print(' '.join(list(map(str, answers))))


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = []
qw = []
for i in range(len(a)):
	b.append(a[i])
	q = []
	for j in range(len(b) - 1):
		q.append(b[j])
	c = 0
	q.sort()
	q.insert(0, a[i])
	while sum(q) > m:
		q.pop()
		c = c + 1
	qw.append(c)
for i in range(len(qw)):
	print(qw[i], end=' ')


(n, m) = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
sum_here = 0
for i in range(n):
	sum_here += arr[i]
	j = p = 0
	sh = sum_here
	el = sorted(arr[:i], reverse=True)
	while sh > m:
		sh -= el[j]
		p += 1
		j += 1
	print(p, end=' ')


(n, m) = map(int, input().split())
t = list(map(int, input().split()))
ans = []
for i in range(n):
	if sum(t[:i + 1]) <= m:
		ans.append(0)
	else:
		remain = sum(t[:i + 1]) - m
		fail_student = sorted(t[:i], reverse=True)
		for j in range(i):
			remain -= fail_student[j]
			if remain <= 0:
				ans.append(j + 1)
				break
print(' '.join(map(str, ans)))


def ri():
	return [int(i) for i in input().split()]

def fl(a, b):
	return abs(a - b)

def main(n, m, t):
	if m >= t[0]:
		print(0, end=' ')
	else:
		print(1, end=' ')
	for i in range(1, len(t)):
		if i == 4:
			asddd = 1
			pass
		new = t[:i]
		new.sort()
		mt = m
		ans = 0
		sm = sum(new)
		while mt < sm + t[i]:
			sm -= new.pop()
			ans += 1
		print(ans, end=' ')
(n, m) = ri()
t = ri()
main(n, m, t)


a = []
total = 0

def binary_search(n, l):
	first = 0
	last = len(l) - 1
	found = False
	mid = (first + last) // 2
	while first <= last and (not found):
		mid = (first + last) // 2
		if l[mid] == n:
			found = True
		elif n < l[mid]:
			last = mid - 1
		else:
			first = mid + 1
	if found:
		return mid
	else:
		return first
(n, M) = map(int, input().split())
t = [int(x) for x in input().split()]
a = []
total = 0
lena = 0
for i in range(n):
	if total + t[i] <= M:
		if i <= lena:
			print('0', end=' ')
		else:
			print(i - lena, end=' ')
		a.insert(binary_search(t[i], a), t[i])
		lena += 1
		total += t[i]
	else:
		compare = total + t[i] - M
		s = 0
		count = 0
		for j in range(lena - 1, -1, -1):
			if s < compare:
				s += a[j]
				count += 1
			else:
				break
		print(count + i - lena, end=' ')
		if t[i] < a[lena - 1]:
			total -= a.pop(lena - 1)
			a.insert(binary_search(t[i], a), t[i])
			total += t[i]


(n, d) = map(int, input().split())
l = list((int(i) for i in input().split()))
m = []
sum = 0
for i in l:
	sum += i
	m.append(sum)
k = []
for i in range(len(m)):
	if m[i] <= d:
		k.append(0)
	else:
		alig = l[:i]
		su = m[i]
		alig.sort(reverse=True)
		count = 0
		for j in alig:
			su -= j
			if su <= d:
				count += 1
				k.append(count)
				break
			else:
				count += 1
print(' '.join(map(str, k)))


(n, M) = list(map(int, input().split(' ')))
time = list(map(int, input().split()))
ans_list = []
for a in range(n):
	leave = 0
	time_reql = time[:a + 1]
	time_req = sum(time_reql)
	time_sort = time_reql[:-1]
	time_sort.sort(reverse=True)
	while time_req > M:
		time_req = time_req - time_sort[leave]
		leave = leave + 1
	ans_list.append(str(leave))
ans = ' '.join(ans_list)
print(ans)


def Terentii(T, n, s):
	k = 0
	while T > n:
		T -= max(s)
		del s[s.index(max(s))]
		k += 1
	return k
n = []
s = []
n = list(map(int, input().split()))
s = list(map(int, input().split()))
F = ''
for i in range(1, n[0] + 1):
	T = 0
	for j in range(i):
		T += s[j]
	F += str(Terentii(T, int(n[1]), s[0:i - 1])) + ' '
print(F)


def factorial(n):
	if n == 1:
		return 1
	if n == 0:
		return 1
	return n * factorial(n - 1)

def cnk(n, k):
	if k > n:
		return 0
	return factorial(n) / (factorial(n - k) * factorial(k))

def main():
	(n, m) = map(int, input().split())
	students = list(map(int, input().split()))
	for i in range(len(students)):
		count = 0
		cur_stud = students[:i]
		cur_stud.sort()
		while students[i] + sum(cur_stud) > m:
			count += 1
			cur_stud.pop()
		print(count, end=' ')
main()


(n, M) = map(int, input().split())
arr = list(map(int, input().split()))
for i in range(n):
	cnt = sum(arr[:i + 1])
	tmp = arr[:i]
	tmp.sort()
	tmp = tmp[::-1]
	if len(tmp) == 0:
		print(0, end=' ')
	else:
		j = 0
		while cnt > M:
			cnt -= tmp[j]
			j += 1
		print(j, end=' ')


import heapq
(n, M) = map(int, input().split())
ts = map(int, input().split())
minh = []
maxh = []
s = 0
for t in ts:
	while s + t > M:
		e = -1 * heapq.heappop(maxh)
		heapq.heappush(minh, e)
		s -= e
	while minh and minh[0] + s + t <= M:
		e = heapq.heappop(minh)
		heapq.heappush(maxh, -1 * e)
		s += e
	print(len(minh), end=' ')
	if maxh and t <= -1 * maxh[0]:
		heapq.heappush(maxh, -1 * t)
		s += t
	elif minh and t >= minh[0]:
		heapq.heappush(minh, t)
	else:
		heapq.heappush(maxh, -1 * t)
		s += t


(n, m) = list(map(int, input().split()))
h = list(map(int, input().split()))
p = []
d = []
d.append(0)
for i in range(1, n):
	p.append(h[i - 1])
	p.sort()
	k = sum(p)
	l = 0
	while k + h[i] > m:
		k -= p[len(p) - 1 - l]
		l += 1
	d.append(l)
print(*d)


(n, m) = list(map(int, input().split()))
A = [int(x) for x in input().split()]
R = []
S = []
for a in A:
	s = sum(S)
	i = len(S)
	while s + a > m:
		i -= 1
		s -= S[i]
	R.append(len(S) - i)
	S.append(a)
	S.sort()
print(*R)


import heapq as hp
import sys
input = sys.stdin.readline
(N, M) = map(int, input().split())
A = list(map(int, input().split()))
q = []
s = 0
ans = []
for a in A:
	qq = q[:]
	hp.heappush(q, -a)
	s += a
	c = 0
	ss = s
	while ss > M:
		b = -hp.heappop(qq)
		ss -= b
		c += 1
	ans.append(c)
for a in ans:
	print(a, end=' ')
print()


nM = input().split()
n = int(nM[0])
M = int(nM[1])
total_minutes = input().split()
for i in range(n):
	total_minutes[i] = int(total_minutes[i])
for i in range(n):
	count = 0
	count_minutes = sum(total_minutes[:i]) + total_minutes[i]
	if count_minutes > M:
		j = i
		sorted_count_minutes = sorted(total_minutes[:j])
		while sum(sorted_count_minutes) + total_minutes[i] > M:
			j -= 1
			sorted_count_minutes = sorted(sorted_count_minutes[:j])
			count += 1
	print(count, end=' ')


def partition(arr, low, high):
	i = low - 1
	pivot = arr[high]
	for j in range(low, high):
		if arr[j] <= pivot:
			i = i + 1
			(arr[i], arr[j]) = (arr[j], arr[i])
	(arr[i + 1], arr[high]) = (arr[high], arr[i + 1])
	return i + 1

def quickSort(arr, low, high):
	if low < high:
		pi = partition(arr, low, high)
		quickSort(arr, low, pi - 1)
		quickSort(arr, pi + 1, high)

def ret(t, i, val):
	quickSort(t, 0, i - 1)
	ret = 0
	for k in range(0, i):
		if t[k] <= val:
			val -= t[k]
		else:
			ret += 1
	return ret
(n, m) = input().split(' ')
n = int(n)
m = int(m)
t = list(map(int, input().split(' ')))
a = [0] * n
for i in range(n):
	if i == 0:
		if t[0] <= m:
			a[0] = 0
	else:
		a[i] = ret(t, i, m - t[i])
for x in range(0, n):
	print(a[x], end=' ')


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
ans = []
for i in range(n):
	s = sum(a[:i + 1])
	if s <= m:
		ans.append(0)
	else:
		count = 0
		k = set()
		c = sorted(a[:i])
		while s > m:
			x = c.pop()
			s -= x
			count += 1
		ans.append(count)
print(' '.join(map(str, ans)))


(n, m) = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
ans = [0] * n
curr_sum = 0
for i in range(len(arr)):
	curr_sum += arr[i]
	if curr_sum > m:
		c = 0
		temp = curr_sum
		sub = sorted(arr[:i])
		for j in range(i - 1, -1, -1):
			temp -= sub[j]
			c += 1
			if temp <= m:
				break
		ans[i] = c
	else:
		ans[i] = 0
print(*ans)


from bisect import insort_left as bl
import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
su = 0
for i in range(n):
	su += a[i]
	if su > m:
		arr = a[:i]
		arr = sorted(arr, reverse=True)
		suh = su
		t = 0
		while suh > m:
			suh -= arr[t]
			t += 1
		print(t, end=' ')
	else:
		print(0, end=' ')


t = list(map(int, input().split(' ')))
n = t[0]
m = t[1]
t = list(map(int, input().split(' ')))
s = []
ans = []
q = 0
for i in range(n):
	q = q + t[i]
	z = q
	if q <= m:
		ans.append(0)
	else:
		a = t[:i]
		a.sort(reverse=True)
		j = 0
		c = 0
		while z > m:
			z = z - a[j]
			j += 1
			c += 1
		ans.append(c)
for i in range(n):
	print(ans[i], end=' ')


import bisect
(n, M) = map(int, input().split())
nums = [int(x) for x in input().split()]
cum = []
res = []
seen = []
for i in nums:
	if len(cum) == 0:
		cum.append(i)
		seen.append(i)
		res.append(0)
	else:
		rem = M - i
		pos = bisect.bisect(cum, rem)
		res.append(len(cum) - pos)
		inpos = bisect.bisect(seen, i)
		bisect.insort(seen, i)
		if inpos == 0:
			cum = [i] + [x + i for x in cum]
		else:
			cum = cum[:inpos] + [i + cum[inpos - 1]] + [x + i for x in cum[inpos:]]
resstr = ' '.join([str(x) for x in res])
print(resstr)


(n, M) = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
d = {}
res = [0 for x in range(len(t))]
sum = 0
for i in range(len(t)):
	if sum + t[i] <= M:
		if d.__contains__(t[i]) == False:
			d[t[i]] = 1
		else:
			d[t[i]] = d[t[i]] + 1
		sum += t[i]
		res[i] = 0
	else:
		tmp_sum = sum
		tmp_ans = 0
		for key in sorted(d.keys(), reverse=True):
			if tmp_sum - d[key] * key + t[i] <= M:
				if (tmp_sum + t[i] - M) % key == 0:
					cnt = int((tmp_sum + t[i] - M) / key)
				else:
					cnt = round(float(tmp_sum + t[i] - M) / key + 0.5)
				tmp_ans += cnt
				break
			else:
				tmp_sum -= d[key] * key
				tmp_ans += d[key]
		if d.__contains__(t[i]) == False:
			d[t[i]] = 1
		else:
			d[t[i]] = d[t[i]] + 1
		sum += t[i]
		res[i] = tmp_ans
print(*res, sep=' ')


(n, m) = list(map(int, input().split()))
arr = list(map(int, input().split()))
res = [0]
for i in range(1, n):
	s = arr[i]
	temp = sorted(arr[:i])
	cnt = 0
	for j in temp:
		if s > m:
			break
		cnt += 1
		s += j
	if s <= m:
		res.append(0)
	else:
		res.append(i - cnt + 1)
print(*res)


import sys
inf = float('inf')
mod = 1000000007

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline()

def int1():
	return int(input())
import string
import math
from itertools import combinations

def main():
	(n, k) = get_array()
	a = get_array()
	b = []
	for i in a:
		b.append(i)
	s = 0
	i = 0
	l = []
	while i < len(a):
		s = s + a[i]
		if s <= k:
			l.append(a[i])
			a[i] = 0
		i = i + 1
	l.sort(reverse=True)
	i = 0
	while i < n:
		if a[i] != 0:
			m = 0
			s1 = sum(b[:i + 1])
			j = 0
			y1 = 0
			while j < len(l):
				m = m + l[j]
				if s1 - m > k:
					y1 = y1 + 1
				if s1 - m <= k:
					y1 = y1 + 1
					break
				j = j + 1
			a[i] = y1
			l.append(b[i])
			l.sort(reverse=True)
		i = i + 1
	print(*a)
main()


(n, m) = map(int, input().split())
t = list(map(int, input().split()))
sums = [t[0]] * n
print(0, end=' ')
for i in range(1, n):
	sums[i] = sums[i - 1] + t[i]
	diff = 0
	if sums[i] > m:
		tmp_sum = sums[i]
		while tmp_sum > m:
			diff += 1
			tmp_sum -= t[i - diff]
	print(diff, end=' ')
	t[:i + 1] = sorted(t[:i + 1])


(n, total) = map(int, input().split())
time = list(map(int, input().split()))
final = [0]
new = [time[0]]
till_now = time[0]
for i in range(1, n):
	till_now += time[i]
	if till_now <= total:
		final.append(0)
	else:
		new.sort(reverse=True)
		count = 0
		pres = till_now
		while pres > total:
			pres -= new[count]
			count += 1
		final.append(count)
	new.append(time[i])
for q in final:
	print(q, end=' ')
print()


import heapq
(n, m) = list(map(int, input().split()))
arr = list(map(int, input().split()))
pre = [arr[0]]
for i in range(1, n):
	pre.append(pre[-1] + arr[i])
ans = []
temp = []
for i in range(n):
	if pre[i] <= m:
		ans.append(0)
	else:
		rem = temp[:]
		rem.sort()
		x = pre[i]
		cnt = 0
		for j in range(len(rem) - 1, -1, -1):
			x = x - rem[j]
			cnt += 1
			if x <= m:
				break
		ans.append(cnt)
	temp.append(arr[i])
print(*ans)


(n, M) = map(int, input().split())
t = [int(z) for z in input().split()]
for i in range(n):
	r = 0
	a = sorted(t[:i])
	b = t[i]
	while sum(a) + b > M:
		a.pop(-1)
		r += 1
	print(r, end=' ')


(X, Students) = (list(map(int, input().split())), list(map(int, input().split())))
for i in range(X[0]):
	(Count, Temp, Sum) = (0, X[1], sum(Students[:i]) + Students[i])
	if Sum <= X[1]:
		print(0, end=' ')
		continue
	else:
		STemp = sorted(Students[:i], reverse=True)
		for j in range(i):
			if X[1] >= Sum:
				break
			(Count, Sum) = (Count + 1, Sum - STemp[j])
	print(Count, end=' ')


(n, m) = map(int, input().split())
qw = [int(i) for i in input().split()]
lk = []
lk.append(0)
b = 0
lki = []

def insert(arr, elem):
	if len(arr) >= 110:
		if arr[-1] >= elem:
			return
		arr[-1] = elem
	else:
		arr.append(elem)
	for i in range(len(arr) - 1, 0, -1):
		if arr[i] > arr[i - 1]:
			(arr[i], arr[i - 1]) = (arr[i - 1], arr[i])
for i in range(1, n):
	b += qw[i - 1]
	insert(lki, qw[i - 1])
	if m >= b + qw[i]:
		lk.append(0)
		continue
	z = 0
	rest = b + qw[i] - m
	for u in range(len(lki)):
		z += lki[u]
		if rest <= z:
			lk.append(u + 1)
			break
print(*lk)


(n, m) = list(map(int, input().split()))
array = list(map(int, input().split()))
res = []

def sumWithout(mas, indexes):
	res = 0
	for i in range(len(mas)):
		if not i in indexes:
			res += mas[i]
	return res

def maxWithout(mas, indexes):
	res = -1
	resInd = 0
	for i in range(len(mas)):
		if not i in indexes and res < mas[i]:
			res = mas[i]
			resInd = i
	return resInd
prev = []
for t in array:
	if sum(prev) + t > m:
		iskl = []
		minRes = 0
		while sumWithout(prev, iskl) + t > m:
			iskl += [maxWithout(prev, iskl)]
			minRes += 1
		res += [minRes]
	else:
		res += [0]
	prev += [t]
print(' '.join((str(x) for x in res)))


(n, m) = map(int, input().split())
ticket = list(map(int, input().split()))
sum = 0
for i in range(n):
	sum += ticket[i]
	if sum <= m:
		print(0, end=' ')
	else:
		tmp = sorted(ticket[0:i])
		tmpSum = sum
		c = 0
		index = i - 1
		while True:
			if tmpSum <= m:
				print(c, end=' ')
				break
			else:
				tmpSum -= tmp[index]
				index -= 1
				c += 1


t = input().split(' ')
n = int(t[0])
m = int(t[1])
li = []
re = []
s = input().split(' ')
for i in range(n):
	li.append(int(s[i]))
	re.append(int(s[i]))
f = []
if li[0] > m:
	f.append(1)
else:
	f.append(0)
for i in range(1, n):
	k = []
	k = sorted(re[:i])
	s = li[i]
	c = 0
	g = 0
	for j in range(len(k)):
		if s > m:
			c = len(k) + 1 - j
			g = j
			break
		else:
			g = j
			s += k[j]
	if s > m and c == 0:
		c = len(k) - g
	f.append(c)
for i in range(n):
	print(f[i], end=' ')


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

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def si():
	return input()
(n, m) = mi()
a = li()
ans = []
ans.append(0)
for i in range(1, n):
	x = m - a[i]
	b = a[:i]
	b.sort()
	c1 = 0
	for j in range(len(b)):
		x -= b[j]
		c1 += 1
		if x < 0:
			c1 -= 1
			break
	ans.append(i - c1)
print(*ans)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
prev = 0
pref = []
for i in range(n):
	pref.append(prev + l[i])
	prev += l[i]
ans = []
lo = []
for i in range(len(l)):
	if pref[i] <= m:
		ans.append(0)
		lo.append(l[i])
	else:
		z = pref[i]
		z -= l[i]
		count = 0
		lo.sort(reverse=True)
		k = l[i]
		for i in lo:
			if k + z - i > m:
				count += 1
				z -= i
			else:
				count += 1
				break
		ans.append(count)
		lo.append(k)
print(*ans)


(n, m) = map(int, input().split())
l = [int(x) for x in input().split()]
ans = []
for i in range(len(l)):
	a = m - l[i]
	arr = sorted(l[:i])
	a -= sum(arr)
	ct = 0
	while a < 0:
		x = arr[-1]
		arr.pop()
		a += x
		ct += 1
	ans.append(ct)
print(*ans)


nM = list(map(int, input().split()))
Times = list(map(int, input().split()))
Arr = []
for i in range(nM[0]):
	j = 0
	Temp = Times[:i]
	Temp1 = Times[:i + 1]
	while sum(Temp1) > nM[1]:
		j += 1
		ttt = max(Temp)
		Temp.pop(Temp.index(max(Temp)))
		Temp1.pop(Temp1.index(ttt))
	print(j, end=' ')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
(n, M) = map(int, input().split())
l = list(map(int, input().split()))
k = [0] * 100
a = [0] * (n + 1)
ans = []
for i in range(1, n + 1):
	a[i] += a[i - 1] + l[i - 1]
for i in range(1, n + 1):
	if a[i] <= M:
		ans.append(0)
	else:
		d = l[:i - 1]
		asi = 0
		d.sort(reverse=True)
		for j in range(len(d)):
			if a[i] <= M:
				break
			else:
				a[i] -= d[j]
				asi += 1
		ans.append(asi)
print(*ans, sep=' ')


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

def arr_sum(s):
	summ = 0
	for i in range(len(s)):
		summ += s[i]
	return summ
for i in range(n):
	t = s[:i + 1]
	ans = 0
	while arr_sum(t) > m:
		del t[t.index(max(t[:len(t) - 1]))]
		ans += 1
	print(ans, end=' ')


(n, m) = map(int, input().split())
a = [int(i) for i in input().split()]
for i in range(n):
	c = m - a[i]
	b = sorted(a[:i], reverse=True)
	s = sum(b)
	j = 0
	while s > c:
		s -= b[j]
		j += 1
	print(j, end=' ')


(n, M) = map(int, input().split())
t = list(map(int, input().split()))
for i in range(n):
	if sum(t[:i + 1]) <= M:
		print(0, end=' ')
	else:
		s = 0
		_t = sorted(t[:i])
		while sum(_t[:i - s]) > M - t[i]:
			s += 1
		print(s, end=' ')


def Lower_bound(arr, l, r, x, val):
	while l < r:
		mid = (l + r) // 2
		if x + arr[mid] >= val:
			r = mid
		else:
			l = mid + 1
	if x + arr[l] >= val:
		return l - 1
	else:
		return l
(n, m) = map(int, input().split())
A = list(map(int, input().split()))
pre = [0] * n
pre[0] = A[0]
for i in range(1, n):
	pre[i] = pre[i - 1] + A[i]
Ans = [0] * n
for i in range(1, n):
	if m - pre[i] >= 0:
		Ans[i] = 0
	else:
		val = pre[i]
		b = sorted(A[:i])
		c = 0
		for j in range(i - 1, -1, -1):
			if m - val >= 0:
				break
			val -= b[j]
			c += 1
		Ans[i] = c
print(*Ans)


def charu(m):
	global l1
	j = 0
	le = len(l1)
	while l1[j] < m:
		j += 1
		if j == le:
			break
	l1 = l1[:j] + [m] + l1[j:]
(a, b) = list(map(int, input().split()))
l = list(map(int, input().split()))
l1 = [l[0]]
l2 = [0]
su = 0
for i in range(1, a):
	k = 0
	su += l[i - 1]
	su1 = su
	while b - l[i] < su1:
		su1 -= l1[-k - 1]
		k += 1
	l2.append(k)
	charu(l[i])
print(*l2)


arr = list(map(int, input().split()))
(n, m) = (arr[0], arr[1])
s = str(input())
a = [int(i) for i in s.split()]
answers = []
s = 0
count = 0
max_val = 0
k = 0
arr = [0 for i in range(101)]
for elem in a:
	if s + elem > m:
		i = max_val
		s2 = s
		c2 = count
		while s2 + elem > m:
			if s2 - arr[i] * i + elem <= m:
				ans = k - c2 + (arr[i] - (m - elem - (s2 - arr[i] * i)) // i)
				s2 -= i * (arr[i] - (m - elem - (s2 - arr[i] * i)) // i)
			else:
				s2 -= arr[i] * i
				c2 -= arr[i]
				i -= 1
		if elem < max_val:
			arr[elem] += 1
			arr[max_val] -= 1
			s = s - max_val + elem
			j = max_val
			while arr[j] < 1:
				j -= 1
			max_val = j
	else:
		arr[elem] += 1
		s += elem
		ans = k - count
		count += 1
		if elem > max_val:
			max_val = elem
	answers.append(str(ans))
	k += 1
print(' '.join(answers))


(n, m) = map(int, input().split())
arr = [int(z) for z in input().split()]

def binsearch(nums, target):
	left = 0
	right = len(nums) - 1
	while left <= right:
		mid = (left + right) // 2
		if nums[mid] == target:
			return mid
		elif nums[mid] > target:
			right = mid - 1
		elif nums[mid] < target:
			left = mid + 1
	return left
prefsums = [arr[0]]
for i in range(1, n):
	prefsums.append(arr[i] + prefsums[i - 1])
res = []
for i in range(n):
	if prefsums[i] <= m:
		res.append(0)
	else:
		c = prefsums[i] - m
		b = 0
		portion = sorted(arr[:i], reverse=True)
		while c > 0:
			c -= portion[b]
			b += 1
		res.append(b)
print(*res)


m = int(input().split(' ')[1])
ln = [int(i) for i in input().split(' ')]
arr = []
sm = 0
for i in range(0, len(ln)):
	sm += ln[i]
	if sm <= m:
		arr.append(0)
	else:
		fsm = sm
		j = i - 1
		nln = sorted(ln[:j + 1])
		while j > 0:
			fsm -= nln[j]
			if fsm <= m:
				break
			j -= 1
		arr.append(i - j)
print(' '.join([str(i) for i in arr]))


ll = lambda : list(map(int, input().split()))
testcases = 1

def find(l, i, m, req):
	l = l[:i]
	l = sorted(l)
	l = reversed(l)
	l = list(l)
	td = sum(l)
	ans = 0
	while m - td < req:
		ans += 1
		td -= l[ans - 1]
	return ans
for testcase in range(testcases):
	[n, m] = ll()
	l = ll()
	ans = [0] * n
	for i in range(1, n):
		ans[i] = find(l, i, m, l[i])
	print(*ans)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
s = 0
for j in range(n):
	s += l[j]
	if s <= m:
		print(0, end=' ')
	else:
		temp = s
		index = j - 1
		count = 0
		x = l[0:j]
		x.sort()
		while temp > m:
			temp -= x[index]
			index -= 1
			count += 1
		print(count, end=' ')


(n, M) = map(int, input().split())
t = list(map(int, input().split()))
prefix_sum = 0
for i in range(n):
	max_ = M - t[i]
	cur_sum = prefix_sum
	prefix_t = sorted(t[:i], reverse=True)
	cnt = 0
	while cur_sum > max_:
		cur_sum -= prefix_t[cnt]
		cnt += 1
	print(cnt, end=' ')
	prefix_sum += t[i]


l = list(map(int, input().split()))
su = 0
final = []
lp = list(map(int, input().split()))
for i in range(l[0]):
	li = []
	su = 0
	n = 0
	for j in range(i + 1):
		su += lp[j]
	if su <= l[1]:
		final.append(n)
	else:
		for j in range(i):
			li.append(lp[j])
		li.sort(reverse=True)
		while su > l[1]:
			su -= li[0]
			li.pop(0)
			n += 1
		final.append(n)
print(*final, sep=' ')


I = lambda : map(int, input().split())
(_, M) = I()
T = list(I())
for (i, t) in enumerate(T):
	x = 0
	while sum(sorted(T[:i])[:i - x]) > M - t:
		x += 1
	print(x, end=' ')


(n, m) = map(int, input().split())
s = list(map(int, input().split()))
print('0', end=' ')
for i in range(1, n):
	student_fail = 0
	new_lst = s[:i + 1]
	while sum(new_lst) > m:
		new_lst.remove(max(new_lst[:-1]))
		student_fail += 1
	print(student_fail, end=' ')


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict
import math
import heapq

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
(n, M) = listIn()
t = listIn()
ans = [0] * n
summ = [t[0]]
for i in range(1, n):
	summ.append(t[i] + summ[i - 1])
for i in range(n):
	if summ[i] <= M:
		ans[i] = 0
	else:
		s = summ[i]
		summ_prev = []
		c = 0
		prev = sorted(t[:i], reverse=True)
		for j in range(len(prev)):
			s -= prev[j]
			c += 1
			if s <= M:
				break
		ans[i] = c
print(*ans)


k = input()
(n, M) = k.split()
n = int(n)
M = int(M)
t = [int(t) for t in input().split()]
c = 0
j = 0
for i in t:
	j += 1
	c += i
	if c <= M:
		print('0', end=' ')
	else:
		t1 = t[:j - 1]
		c1 = 0
		c2 = c
		m = max(t1)
		while c2 > M:
			c1 += 1
			t1.remove(m)
			c2 -= m
			if len(t1) != 0:
				m = max(t1)
		print(c1, end=' ')


import heapq
import bisect

def insert(list, n):
	bisect.insort(list, n)
	return list
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
count = a[0]
ans = [0]
li = [a[0]]
heapq.heapify(li)
for i in range(1, n):
	if count + a[i] <= k:
		ans.append(0)
		count += a[i]
		li = insert(li, a[i])
	elif a[i] == k:
		ans.append(i)
		count += a[i]
		li = insert(li, a[i])
	else:
		cnt = 0
		c = 0
		for j in range(len(li) - 1, -1, -1):
			if count - cnt + a[i] <= k:
				break
			else:
				cnt += li[j]
				c += 1
		ans.append(c)
		count += a[i]
		li = insert(li, a[i])
print(*ans)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
sm = 0
ans = []
tm = []
for i in range(len(l)):
	sm += l[i]
	if sm <= m:
		ans.append(0)
		tm.append(l[i])
	else:
		tm.sort(reverse=True)
		k = 0
		ct = 0
		tem = sm
		while tem > m and k < len(tm):
			tem -= tm[k]
			k += 1
			ct += 1
		ans.append(ct)
		tm.append(l[i])
print(' '.join([str(i) for i in ans]))


from sys import stdin, stdout, maxsize as mxs
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
from typing import Counter
from itertools import accumulate
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
(n, k) = mp()
arr = lmp()
cnt = l2d(n + 1, 101)
for i in range(1, n + 1):
	for j in range(1, 101):
		if j == arr[i - 1]:
			cnt[i][j] = cnt[i - 1][j] + 1
		else:
			cnt[i][j] = cnt[i - 1][j]
ansl = []
s = 0
for i in range(n):
	s += arr[i]
	c = 0
	if s > k:
		df = s - k
		for j in range(100, 0, -1):
			x = min(cnt[i][j], ceil(df, j))
			df -= j * x
			c += x
			if df <= 0:
				break
	ansl.append(c)
print(*ansl)


(n, M) = map(int, input().split())
a = list(map(int, input().split()))
b = list()
b.append(0)
c = 0
for i in range(1, n):
	d = sorted(a[0:i], reverse=True)
	sn = sum(d)
	kn = 0
	if sn + a[i] <= M:
		c = 0
	else:
		for j in range(len(d)):
			kn += d[j]
			c += 1
			if sn - kn + a[i] <= M:
				break
	b.append(c)
	c = 0
for i in range(len(b)):
	print(b[i], end=' ')


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
s = 0
for i in range(n):
	s += a[i]
	ss = s
	z = sorted(a[:i], reverse=True)
	j = p = 0
	while ss > m:
		ss -= z[j]
		p += 1
		j += 1
	print(p, end=' ')


(n, M) = [int(x) for x in input().strip().split(' ')]
ti = [int(x) for x in input().strip().split(' ')]
ret = [None] * n
cum = [0] * n
cum[0] = ti[0]
for i in range(1, n):
	cum[i] = ti[i] + cum[i - 1]
for i in range(n):
	if cum[i] <= M:
		ret[i] = str(0)
	else:
		tti = sorted(ti[:i], key=lambda x: -x)
		d = cum[i] - M
		st = 0
		while True:
			d = d - tti[st]
			st += 1
			if d <= 0:
				break
		ret[i] = str(st)
print(' '.join(ret))


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
print(0, end=' ')
for i in range(1, n):
	s = sorted(l[:i])
	total = sum(s) + l[i]
	cnt = 0
	while total > m:
		a = s.pop()
		total -= a
		cnt += 1
	print(cnt, end=' ')
print()


import heapq

def main():
	buf = input()
	buflist = buf.split()
	n = int(buflist[0])
	M = int(buflist[1])
	buf = input()
	buflist = buf.split()
	t = list(map(int, buflist))
	student = []
	minimum = []
	for i in range(n):
		count = 0
		pointer = 0
		while pointer < i:
			if count + student[pointer] <= M - t[i]:
				count += student[pointer]
				pointer += 1
			else:
				break
		minimum.append(i - pointer)
		student.append(t[i])
		student.sort()
	print(' '.join(list(map(str, minimum))))
main()


(n, m) = map(int, input().split())
hihi = list(map(int, input().split()))
(hehe, dem, dem1) = (list(), 0, 0)
for i in range(n):
	hehe = sorted(hihi[0:i])
	for j in range(101):
		dem1 = sum(hehe)
		if hihi[i] + dem1 <= m:
			print(dem, end=' ')
			break
		else:
			hehe = hehe[0:len(hehe) - 1]
			dem += 1
	(hehe, dem1, dem) = (list(), 0, 0)


(n, M) = [int(_) for _ in input().split()]
t = [int(_) for _ in input().split()]
q = []
for x in t:
	mi = M - x
	s = sum(q)
	i = 0
	while mi < s:
		i -= 1
		s -= q[i]
	print(abs(i), end=' ')
	q.append(x)
	for i in range(-1, -len(q), -1):
		if q[i] < q[i - 1]:
			(q[i], q[i - 1]) = (q[i - 1], q[i])


(n, m) = map(int, input().split())
s = list(map(int, input().split()))
r = '0'
for i in range(1, n):
	a = sorted(s[:i], reverse=True)
	b = sum(a) + s[i]
	d = 0
	while 1:
		if b <= m:
			break
		else:
			b -= a[d]
			d += 1
	r += ' ' + str(d)
print(r)


from __future__ import division, print_function
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
from math import ceil, floor, log, sqrt, factorial, pow, pi

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

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p1
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def dfs(v, c):
	if visited[v]:
		if col[v] != c:
			print('-1')
			exit()
		return
	col[v] = c
	visited[v] = 1
	for i in graph[v]:
		dfs(i, c ^ 1)

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph():
	d = {}
	(v, e) = mi()
	for i in range(e):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d.keys():
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(l, n):
	d = {}
	for i in range(1, n + 1):
		if i not in d.keys():
			d[i] = l[i]
		else:
			d[i].append(l[i])
	return d
(n, m) = mi()
l = li()
s = 0
b = []
for i in range(n):
	s += l[i]
	if s <= m:
		b.append(0)
	else:
		z = sorted(l[:i])[::-1]
		x = s
		for j in range(i):
			x -= z[j]
			if x <= m:
				b.append(j + 1)
				break
print(' '.join(map(str, b)))


import sys
read = lambda : sys.stdin.readline().strip()
write = lambda x: sys.stdout.write(x)
(n, m) = map(int, input().split())
t = list(map(int, input().split()))
ans = [0]
for k in range(1, n):
	a = sorted(t[:k])
	s = [t[k], -1]
	for (j, i) in enumerate(a):
		if s[0] + i > m:
			s[1] = j
			break
		else:
			s[0] += i
	if s[1] == -1:
		ans.append(0)
	else:
		ans.append(k - s[1])
print(*ans)


(n, m) = list(map(int, input().split()))
a = list(map(int, input().split()))
from bisect import bisect_left, insort_left
l = []
cnt = 0
r = [0] * n
for (i, x) in enumerate(a):
	if cnt + x <= m:
		insort_left(l, x)
		r[i] = 0
		cnt += x
	else:
		tmp = 0
		for j in range(len(l) - 1, -1, -1):
			tmp += l[j]
			if cnt + x <= m + tmp:
				break
		r[i] = len(l) - j
		insort_left(l, x)
		cnt += x
print(*r)


class BinHeap:

	def __init__(self):
		self.heap = []

	def get_max(self):
		if len(self.heap) > 0:
			return self.heap[0]

	def add_elem(self, elem):
		self.heap.append(elem)
		index = len(self.heap) - 1
		while index > 0 and self.heap[index] > self.heap[(index - 1) // 2]:
			(self.heap[index], self.heap[(index - 1) // 2]) = (self.heap[(index - 1) // 2], self.heap[index])
			index = (index - 1) // 2

	def delete_min(self):
		if len(self.heap) == 0:
			pass
		else:
			elem = self.heap[0]
			(self.heap[0], self.heap[len(self.heap) - 1]) = (self.heap[len(self.heap) - 1], self.heap[0])
			self.heap.pop()
			self.heapfy(0)
			return elem

	def heapfy(self, index):
		left = index * 2 + 1
		right = index * 2 + 2
		size_heap = len(self.heap)
		if size_heap > left and self.heap[left] > self.heap[index]:
			elem = left
		else:
			elem = index
		if size_heap > right and self.heap[right] > self.heap[elem]:
			elem = right
		if elem != index:
			(self.heap[elem], self.heap[index]) = (self.heap[index], self.heap[elem])
			self.heapfy(elem)
arr = list(map(int, input().split()))
(n, m) = (arr[0], arr[1])
arr = list(map(int, input().split()))
heap = BinHeap()
heap.heap
answers = []
s = 0
for i in range(n):
	ans = i - len(heap.heap)
	times = []
	if s + arr[i] > m:
		while s + arr[i] > m:
			times.append(heap.delete_min())
			ans += 1
			s -= times[-1]
		for elem in times:
			heap.add_elem(elem)
			s += elem
		if heap.get_max() > arr[i]:
			s -= heap.delete_min()
			heap.add_elem(arr[i])
			s += arr[i]
	else:
		s += arr[i]
		heap.add_elem(arr[i])
	answers.append(ans)
ans = ''
for elem in answers:
	ans += str(elem) + ' '
print(ans[:-1])


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
k = []
for i in range(1, n):
	b = a[:i]
	b.sort()
	b = b[::-1]
	k.append(b)
ans = [0]
sm = a[0]
for i in range(1, n):
	sm += a[i]
	cnt = 0
	x = 0
	if sm > m:
		y = sm
		for j in range(i):
			x = k[i - 1][j]
			y -= x
			cnt += 1
			if y <= m:
				break
	ans.append(cnt)
for i in range(n):
	print(ans[i], end=' ')


(n, M) = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
for (i, j) in enumerate(arr):
	passed = arr[:i]
	elapsed = sum(passed)
	if elapsed + j > M:
		cnt = 0
		time = elapsed + j
		while time > M:
			cnt += 1
			time -= max(passed)
			passed.pop(passed.index(max(passed)))
		print(cnt, end=' ')
	else:
		print(0, end=' ')


(a, b) = map(int, input().split())
l = list(map(int, input().split()))
c = []
n = 0
for i in range(a):
	n += l[i]
	if n <= b:
		c.append(0)
		continue
	m = n
	l[:i] = sorted(l[:i], reverse=True)
	x = 0
	for j in range(i):
		m = m - l[j]
		x += 1
		if m <= b:
			c.append(x)
			break
for k in range(a):
	print(c[k], end=' ')


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
s = 0
b = []
for i in range(n):
	b.sort()
	temp = 0
	k = 0
	s += a[i]
	if s > m:
		for j in range(len(b) - 1, -1, -1):
			temp += b[j]
			k += 1
			if temp >= s - m:
				break
	print(k, end=' ')
	b.append(a[i])


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
r = '0 '
for i in range(1, a):
	d = []
	for j in range(i):
		d.append(c[j])
	u = 0
	while b - sum(d) - c[i] < 0:
		m = max(d)
		j = 0
		while j < len(d):
			if d[j] == m:
				d.pop(j)
				break
			j += 1
		u += 1
	r += str(u) + ' '
print(r)


import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(100000)
input = sys.stdin.readline

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

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

def read_float():
	return float(input())

def read_float_n():
	return list(map(float, input().split()))

def read_str():
	return input().strip()

def read_str_n():
	return list(map(str, input().split()))

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

def slv(N, M, S):
	ans = []
	for i in range(N):
		m = sum(S[:i + 1])
		if m <= M:
			ans.append(0)
		else:
			s = S[:i]
			s.sort()
			c = 0
			while m > M:
				m -= s.pop()
				c += 1
			ans.append(c)
	return ' '.join(map(str, ans))

def main():
	(N, M) = read_int_n()
	S = read_int_n()
	print(slv(N, M, S))
main()


(n, m) = map(int, input().split())
z = list(map(int, input().split()))
ans = []
csum = 0
for i in range(len(z)):
	csum += z[i]
	if csum <= m:
		ans.append(0)
	else:
		tmparr = z[0:i]
		tcsum = csum
		tmparr.sort(reverse=True)
		for i in range(len(tmparr)):
			tcsum -= tmparr[i]
			if tcsum <= m:
				ans.append(i + 1)
				break
print(*ans)


(n, m) = map(int, input().split())
ti = list(map(int, input().split()))
for i in range(n):
	t = list(ti[:i])
	while True:
		if sum(t) + ti[i] <= m:
			break
		del t[t.index(max(t))]
	print(i - len(t), end=' ')
print()


(n, m) = map(int, input().split())
l = [int(i) for i in input().split()]
pre = [0] * (n + 1)
for i in range(1, n + 1):
	pre[i] = pre[i - 1] + l[i - 1]
ans = [0] * n
arr = []
for i in range(n):
	if pre[i + 1] <= m:
		ans[i] = 0
		arr.append(l[i])
	else:
		arr.sort()
		rem = m - l[i]
		c = 0
		sm = pre[i]
		j = len(arr) - 1
		while sm > rem:
			sm -= arr[j]
			j -= 1
			c += 1
		ans[i] = c
		arr.append(l[i])
print(*ans)


(n, m) = map(int, input().split())
t = list(map(int, input().split()))
su = []
ans = []
for i in range(n):
	su.append(sum(t[:i + 1]))
for i in range(n):
	if su[i] <= m:
		ans.append(0)
	else:
		cnt = 0
		k = []
		for z in range(i):
			k.append(t[z])
		k.sort(reverse=True)
		j = 0
		while su[i] > m:
			su[i] -= k[j]
			cnt += 1
			j += 1
		ans.append(cnt)
for i in ans:
	print(i, end=' ')


(n, m) = [int(x) for x in input().split()]
times = [int(x) for x in input().split()]
import heapq

def calculate_times(times, m):
	prefix_sum = 0
	q = []
	res = []
	for t in times:
		prefix_sum += t
		if prefix_sum <= m:
			res.append(0)
		else:
			count = 0
			poped = []
			diff = prefix_sum - m
			while diff > 0:
				count += 1
				val = heapq.heappop(q)
				diff += val
				poped.append(val)
			for val in poped:
				heapq.heappush(q, val)
			res.append(count)
		heapq.heappush(q, -t)
	return res
print(' '.join([str(x) for x in calculate_times(times, m)]))


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = []
c = []
s = 0
for i in a:
	cnt = 0
	v = 0
	s = s + i
	if s > k:
		while s > k:
			b.sort()
			l = len(b) - 1 - cnt
			s -= b[l]
			v += b[l]
			cnt += 1
		c.append(cnt)
		b.append(i)
		s += v
	else:
		b.append(i)
		c.append(0)
for i in c:
	print(i, end=' ')


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
count = 0
b = []
for i in range(n):
	b = []
	for j in range(i):
		b.append(a[j])
	b.sort()
	count = sum(b) + a[i]
	c = 0
	while count > s:
		count -= b[-1]
		b.pop(-1)
		c += 1
	print(c, end=' ')
print()


import bisect
(a, b) = map(int, input().split())
A = list(map(int, input().split()))
B = []
IN = []
kk = 0
for i in range(len(A)):
	kkl = int(kk) + A[i]
	j = 0
	while kkl > b and j < len(B):
		kkl -= B[-j - 1]
		j += 1
	IN.append(j)
	bisect.insort(B, A[i])
	kk += A[i]
print(*IN)


(n, m) = map(int, input().split())
t = list(map(int, input().split()))
t2 = []
cur = 0
res = []
for i in t:
	if sum(t2) + i <= m:
		t2.append(i)
		res.append(0)
	else:
		j = 0
		t3 = t2[:]
		while sum(t3) + i > m:
			t3.remove(max(t3))
			j += 1
		t2.append(i)
		res.append(j)
for i in res:
	print(i, end=' ')


import math
import os
import random
import re
import sys
(n, m) = map(int, input().split())
ans = 0
a = list(map(int, input().split()))
for i in range(n):
	temp = sorted(a[:i])
	sum = a[i]
	j = 0
	while j < len(temp):
		sum = sum + temp[j]
		if sum <= m:
			j = j + 1
		else:
			break
	ans = len(temp) - j
	print(ans, end=' ')


import itertools
from heapq import heapify, heappush, heappop
import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
t = list(map(int, input().split()))
tsum = list(itertools.accumulate(t))
ans = []
for i in range(n):
	if tsum[i] <= m:
		ans.append(0)
	else:
		heap = [-k for k in t[:i]]
		heapify(heap)
		remain = sum(t[:i]) - m
		count = 0
		for j in range(i, n):
			uselist = []
			remain += t[j]
			while remain > 0:
				count += 1
				use = heappop(heap)
				remain += use
				uselist.append(use)
			else:
				ans.append(count)
				uselist.sort(reverse=True)
			summ = 0
			for uses in uselist[:100]:
				heappush(heap, uses)
				remain -= uses
				summ -= uses
				count -= 1
				if summ > 100:
					break
			heappush(heap, -t[j])
		break
print(' '.join(map(str, ans)))


(n, m) = map(int, input().split())
t = list(map(int, input().split()))
mm = []
ss = 0
for i in range(n):
	if sum(mm) + t[i] <= m:
		print(0, end=' ')
	else:
		mm = sorted(mm)
		ss = sum(mm)
		xx = 0
		tmp = []
		while ss + t[i] > m:
			tmp.append(mm.pop())
			ss -= tmp[-1]
			xx += 1
		print(xx, end=' ')
		while len(tmp) != 0:
			mm.append(tmp.pop())
	mm.append(t[i])


from bisect import insort
(n, m) = [int(x) for x in input().split()]
students = [int(x) for x in input().split()]
s = 0
heap = []
std = []
for i in students:
	if s + i > m:
		std = heap.copy()
		t = 0
		q = s
		while q + i > m:
			q -= std.pop()
			t += 1
		print(t, end=' ')
	else:
		print('0 ', end='')
	s += i
	insort(heap, i)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
c = 0
C = []
ans = []
for i in range(n):
	c += a[i]
	if i != 0:
		C.append(a[i - 1])
		C.sort()
	b = c
	d = 0
	m = 1
	while b > k:
		d += 1
		s = C[len(C) - m]
		m += 1
		b -= s
	ans.append(d)
for i in ans:
	print(i, end=' ')


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

def meth(arr):
	val = arr[-1]
	arr = arr[0:-1]
	arr.sort()
	count = 0
	fl = 0
	br = 0
	for i in range(len(arr)):
		if val > m:
			if fl == 1:
				count -= 1
			br = 12
			break
		else:
			fl = 1
			val += arr[i]
			count += 1
	if br == 0 and val > m:
		if fl == 1:
			count -= 1
	print(len(arr) - count, end=' ')
for i in range(n):
	meth(a[0:i + 1])
print()


(n, m) = map(int, input().split())
lst = [int(i) for i in input().split()]
pases = [0]
kk = lst[0]
for i in range(1, len(lst)):
	kk += lst[i]
	if kk <= m:
		pases.append(0)
	else:
		k1 = sorted(lst[:i])
		temp_sum = kk
		ii = len(k1) - 1
		cnt = 0
		while temp_sum > m:
			temp_sum -= k1[ii]
			cnt += 1
			ii -= 1
		pases.append(cnt)
print(*pases)


(n, M) = map(int, input().split())
timeList = list(map(int, input().split()))
answerList = []
for i in range(n):
	currentList = timeList[:i + 1]
	s = sum(currentList)
	answer = 0
	if s <= M:
		answerList.append(0)
		continue
	else:
		while s > M:
			m = max(currentList[:len(currentList) - 1])
			currentList.remove(m)
			s = sum(currentList)
			answer += 1
	answerList.append(answer)
print(' '.join(map(str, answerList)))


(n, m) = map(int, input().split())
t = list(map(int, input().split()))
tIndex = {}
tIndexSum = {}
s = 0
for i in range(n):
	r = 0
	if s + t[i] > m:
		keys = list(tIndex.keys())
		keys.sort(reverse=True)
		s1 = s
		for k in keys:
			if s1 - tIndex[k] * k + t[i] > m:
				s1 -= tIndex[k] * k
				r += tIndex[k]
			else:
				r += (s1 + t[i] - m) // k
				s1 -= (s1 + t[i] - m) // k * k
				if s1 + t[i] > m:
					s1 -= k
					r += 1
			if s1 + t[i] <= m:
				break
	print(r, end=' ')
	if not t[i] in tIndex:
		tIndex[t[i]] = 0
	tIndex[t[i]] += 1
	if not t[i] in tIndexSum:
		tIndexSum[t[i]] = 0
	tIndexSum[t[i]] += t[i]
	s += t[i]


(n, m) = map(int, input().split())
t = list(map(int, input().split()))
curr = 0
arr = []
ans = []
for i in range(n):
	curr += t[i]
	if curr <= m:
		ans.append(0)
	else:
		temp = sorted(arr, reverse=True)
		cc = 0
		rt = 0
		for j in range(len(temp)):
			cc += temp[j]
			rt += 1
			if curr - cc <= m:
				break
		ans.append(rt)
	arr.append(t[i])
for i in ans:
	print(i, end=' ')
print()


(n, M) = map(int, input().split(' '))
y = list(map(int, input().split()))
c = []
c.append(y[0])
y[0] = 0
j = 1
while j < n:
	s = sum(c)
	if s + y[j] < M:
		c.append(y[j])
		y[j] = 0
	else:
		c = sorted(c)
		s = s + y[j]
		count = 1
		while s > M:
			s = s - c[-count]
			count += 1
		c.append(y[j])
		y[j] = count - 1
	j = j + 1
print(*y)


import heapq
(n, m) = map(int, input().split())
t = [int(x) for x in input().split()]
a = []
heapq.heapify(a)
s = 0
r = []
for tt in t:
	gg = []
	i = 0
	while s > m - tt:
		i += 1
		ss = -heapq.heappop(a)
		s -= ss
		gg.append(-ss)
	heapq.heappush(a, -tt)
	s += tt
	for g in gg:
		heapq.heappush(a, g)
		s += -g
	r.append(i)
print(*r)


(n, m) = map(int, input().split())
lst = list(map(int, input().split()))
ans = [0] * n
stk = []
summ = 0
cur = 0
for i in range(n):
	if summ + lst[i] > m:
		arr = lst[:i].copy()
		arr.sort()
		temp = summ
		j = i - 1
		while j >= 0 and temp + lst[i] > m:
			temp -= arr[j]
			j -= 1
		ans[i] = i - j - 1
	else:
		ans[i] = 0
	summ += lst[i]
print(*ans)


(n, M) = map(int, input().split())
x = list(map(int, input().split()))
cnt = 0
for i in range(n):
	if sum(x[:i + 1]) <= M:
		print(0, end=' ')
	else:
		cur_sum = sum(x[:i + 1])
		for j in range(i, 0, -1):
			b = x[:i]
			b.sort()
			if cur_sum - b[j - 1] > M:
				cur_sum -= b[j - 1]
				cnt += 1
			else:
				cnt += 1
				print(cnt, end=' ')
				cnt = 0
				break


(n, mins) = [int(x) for x in input().split()]
inp = [int(x) for x in input().split()]
lis = list()
total = inp[0]
arr = list()
arr.append(0)
lis.append(inp[0])
for x in range(1, n):
	counter = 0
	total += inp[x]
	tempTotal = total
	if total > mins:
		lis.sort()
	while tempTotal > mins:
		tempTotal -= lis[len(lis) - counter - 1]
		counter += 1
	arr.append(counter)
	lis.append(inp[x])
for i in arr:
	print(i, end=' ')


from heapq import heappush, heappop
(N, M) = map(int, input().split())
List = [int(x) for x in input().split()]
Ans = []
Heap = []
Time = 0
for i in range(N):
	Time += List[i]
	if Time <= M:
		Ans.append(0)
		heappush(Heap, -List[i])
	else:
		Copy = Heap.copy()
		Chahiye = Time - M
		X = 0
		for j in range(len(Ans)):
			X += -heappop(Copy)
			if X >= Chahiye:
				Ans.append(j + 1)
				break
		heappush(Heap, -List[i])
print(*Ans)


(n, m) = map(int, input().split())
t = list(map(int, input().split()))
cur = 0
c = 0
l = []
for i in t:
	if cur + i <= m:
		print('0', end=' ')
		cur += i
		c += 1
		l.append(i)
	else:
		cur += i
		ans = cur
		coun = 0
		l_2 = sorted(l, reverse=True)
		while ans > m:
			ans -= l_2[coun]
			coun += 1
		l.append(i)
		print(coun, end=' ')


from math import *
(n, m) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
for i in range(n):
	s = a[:i]
	s = sorted(s)
	s = s[::-1]
	now = sum(s)
	c = 0
	j = 0
	while j < len(s) and now + a[i] > m:
		now -= s[j]
		j += 1
		c += 1
	print(c, end=' ')
print()


import sys, itertools
(n, m) = map(int, sys.stdin.readline().split())
arr = list(map(int, sys.stdin.readline().split()))
pf = [0] * n
pf[0] = arr[0]
for i in range(1, n):
	pf[i] = pf[i - 1] + arr[i]
ans = [0] * n
for i in range(1, n):
	if pf[i] <= m:
		continue
	else:
		temp = []
		for j in range(i):
			temp.append(arr[j])
		temp.sort()
		cnt = 0
		while temp:
			if sum(temp) + arr[i] <= m:
				break
			temp.pop()
			cnt += 1
		ans[i] = cnt
print(' '.join(map(str, ans)))


def add(n):
	global a
	a.append(n)
	a.sort()
(n, m) = map(int, input().split())
s = list(map(int, input().split()))
ssum = s[0]
a = list()
ans = [0] * n
add(s[0])
for i in range(1, n):
	if ssum + s[i] > m:
		j = len(a) - 1
		temp = ssum
		while temp + s[i] > m:
			ans[i] += 1
			temp -= a[j]
			j -= 1
	ssum += s[i]
	add(s[i])
print(*ans)


import heapq
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
sm = 0
qw = []
for i in range(n):
	if sm + a[i] > m:
		q = []
		ans = 0
		while sm + a[i] > m:
			if len(qw) == 0:
				print('qwqwqwqw')
			e = heapq.heappop(qw)
			sm -= -e
			q.append(e)
			ans += 1
		print(ans, end=' ')
		for x in q:
			heapq.heappush(qw, x)
			sm += -x
		sm += a[i]
		heapq.heappush(qw, -a[i])
	else:
		heapq.heappush(qw, -a[i])
		sm += a[i]
		print(0, end=' ')


(n, t) = list(map(int, input().split()))
l = list(map(int, input().split()))
ans = []
for i in range(1, n + 1):
	s = sum(l[:i])
	count = 0
	if s <= t:
		ans.append(0)
		continue
	else:
		l2 = [x for x in l[:i - 1]]
		while s > t:
			s -= max(l2)
			l2.remove(max(l2))
			count += 1
		ans.append(count)
print(' '.join(map(str, ans)))


(a, b) = list(map(int, input().split()))
kam = list(map(int, input().split()))
lam = []
ans = []
count = 0
for it in kam:
	if count + it <= b:
		ans.append(0)
		count += it
	else:
		jim = count
		kj = 0
		for iit in lam:
			kj += 1
			jim -= iit
			if jim + it <= b:
				ans.append(kj)
				break
			else:
				pass
		count += it
	lam.append(it)
	lam.sort(reverse=True)
print(*ans)


(n, m) = map(int, input().split(' '))
l = list(map(int, input().split(' ')))
li = []
j = 0
while j < n:
	t = l[len(l) - 1]
	l.pop()
	a = list(l)
	a.sort()
	s = 0
	c = 0
	for i in range(0, len(a)):
		s += a[i]
		if s <= m - t:
			c += 1
		else:
			break
	li.append(len(a) - c)
	j += 1
li.reverse()
print(*li, sep=' ')


(n, m) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
res = [0]
suma = a[0]
for i in range(1, n):
	suma += a[i]
	if suma > m:
		cut = a[:i]
		cut = sorted(cut, reverse=True)
		sumb = a[i] + sum(cut)
		for j in range(len(cut)):
			sumb -= cut[j]
			if sumb <= m:
				res.append(j + 1)
				break
	else:
		res.append(0)
print(*res)


[n, M] = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
s = 0
res = []
for i in range(n):
	ti = t[i]
	r = M - ti
	si = s
	if si <= r:
		res.append(0)
	else:
		j = i - 1
		x = 0
		while si > r:
			si -= t[j]
			j -= 1
			x += 1
		res.append(x)
	j = i
	s += t[i]
	while j > 0 and t[j] < t[j - 1]:
		(t[j], t[j - 1]) = (t[j - 1], t[j])
		j -= 1
print(' '.join([str(i) for i in res]))


import bisect
(n, m) = map(int, input().split())
t = list(map(int, input().split()))
max_numbers = []
total_sum = 0
ans = []
for s in t:
	total_sum += s
	if total_sum <= m:
		ans.append(0)
	else:
		total_sub = 0
		num = 0
		for e in max_numbers[::-1]:
			total_sub += e
			num += 1
			if total_sum - total_sub <= m:
				ans.append(num)
				break
	bisect.insort(max_numbers, s)
print(*ans)


def maxSelections(z, A, n, k):
	A.sort()
	sum = z
	count = 0
	for i in range(n - 1):
		sum = sum + A[i]
		if sum > k:
			break
		count += 1
	return count
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
l = []
for i in range(n):
	mn = maxSelections(a[i], a[:i], i + 1, m)
	if i - mn <= 0:
		l.append(0)
	else:
		l.append(i - mn)
print(*l, end=' ')


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
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 list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

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 pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = 1
	rr = []
	for _ in range(t):
		(n, m) = LI()
		a = LI()
		r = []
		t = 0
		q1 = []
		q2 = []
		for (i, c) in enumerate(a):
			if q1 and q2:
				t1 = -heapq.heappop(q1)
				t -= t1
				while q2:
					t2 = heapq.heappop(q2)
					if t2 < t1 and t + t2 + c <= m:
						t += t2
						heapq.heappush(q1, -t2)
					else:
						heapq.heappush(q2, t2)
						break
				if t + t1 + c <= m:
					t += t1
					heapq.heappush(q1, -t1)
				else:
					heapq.heappush(q2, t1)
			while t + c > m:
				t1 = -heapq.heappop(q1)
				t -= t1
				heapq.heappush(q2, t1)
			t += c
			heapq.heappush(q1, -c)
			r.append(i + 1 - len(q1))
		rr.append(JA(r, ' '))
	return JA(rr, '\n')
print(main())


(x, y) = map(int, input().split())
s = list(map(int, input().split()))
tm = []
res = []
sm = 0
for n in range(x):
	sm += s[n]
	if sm > y:
		d = sm - y
		p = 0
		while d > 0:
			d -= tm[p]
			p += 1
		res.append(p)
	else:
		res.append(0)
	tm.append(s[n])
	tm.sort()
	tm.reverse()
print(*res)


(a, b) = map(int, input().split())
s = list(map(int, input().split()))
n = 0
li = []
l = a - 1
for i in range(l):
	li.append([s[i], i])
li[:l] = sorted(li[:l], reverse=True)
u = len(li)
for i in range(a):
	n += s[i]
	if n <= b:
		print(0, end=' ')
		continue
	m = n
	x = 0
	for j in range(l):
		if li[j][1] < i:
			m = m - li[j][0]
			x += 1
			if m <= b:
				print(x, end=' ')
				break


import heapq

def main():
	(n, m) = map(int, input().split())
	heap = []
	time = list(map(int, input().split()))
	ans = []
	total = 0
	for i in range(n):
		if m - total >= time[i]:
			ans.append(0)
		else:
			new = []
			while True:
				curr = heapq.heappop(heap)
				new.append(curr)
				total -= abs(curr)
				if m - total >= time[i]:
					ans.append(len(new))
					break
			for j in new:
				heapq.heappush(heap, j)
				total += abs(j)
		heapq.heappush(heap, -time[i])
		total += time[i]
	for i in ans:
		print(i, end=' ')
main()


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
ans = []
for i in range(n):
	b = sorted(a[:i])
	su = a[i]
	count = 0
	for i in range(len(b)):
		su += b[i]
		if su > m:
			count += 1
			su -= b[i]
	ans.append(count)
print(*ans)


def solve(n, time, seq):
	ans = [0] * n
	before = [101] * n
	index = 0
	while index < n:
		left = 0
		time2 = 0
		time2 += seq[index]
		for i in before:
			if i == 101:
				break
			if time2 + i > time:
				left += 1
			else:
				time2 += i
		ans[index] = left
		before[index] = seq[index]
		before.sort()
		index += 1
	return ans
(n, time) = list(map(int, input().split()))
seq = list(map(int, input().split()))
for x in solve(n, time, seq):
	print(x, end=' ')


import os.path
from math import gcd, floor, ceil
from collections import *
import sys
from heapq import *
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

def li():
	return list(map(int, sys.stdin.readline().split()))

def mp():
	return map(int, sys.stdin.readline().split())

def inp():
	return int(sys.stdin.readline())

def pr(n):
	return sys.stdout.write(str(n) + '\n')

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	(n, m) = mp()
	l = li()
	ans = [0]
	pre = l[0]
	h = [-l[0]]
	for i in range(1, n):
		pre += l[i]
		cur = 0
		x = []
		s = 0
		while h and s < pre - m:
			a = heappop(h)
			x.append(a)
			s -= a
			cur += 1
		for j in x:
			heappush(h, j)
		heappush(h, -l[i])
		ans.append(cur)
	print(*ans)
for _ in range(1):
	solve()


(n, m) = list(map(int, input().split()))
A = list(map(int, input().split()))
Sum = A[0]
S = [A[0]]
for val in A[1:]:
	Sum += val
	S.append(Sum)
for (val, R) in zip(S, range(n)):
	if val <= m:
		print(0, end=' ')
	else:
		count = 1
		Sorted = list(sorted(A[:R]))
		for i in range(R - 1, 0, -1):
			val -= Sorted[i]
			if val <= m:
				break
			count += 1
		print(count, end=' ')
print()


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l2 = []
b = []
for i in range(n):
	if sum(l[0:i + 1]) <= m:
		b.append(0)
	else:
		l2 = []
		l2.extend(l)
		c = 0
		d = sum(l2[0:i + 1])
		while d > m:
			e = max(l2[0:i - c])
			d -= e
			l2.remove(e)
			c += 1
		b.append(c)
for i in b:
	print(i, end=' ')


(n, M) = [int(i) for i in input().split()]
lst = [int(i) for i in input().split()]
a = list()
for j in range(n):
	temp = sorted(lst[:j])
	s = lst[j]
	count = 1
	for y in temp:
		if s + y > M:
			break
		s += y
		count += 1
	a.append(j + 1 - count)
print(*a)


(n, M) = input().split()
n = int(n)
M = int(M)
l = []
for x in input().split():
	l.append(int(x))
for i in range(n):
	if sum(l[:i + 1]) > M:
		x = sorted(l[:i])
		c = 0
		k = 0
		for j in range(i):
			k = k + x[i - 1 - j]
			c = c + 1
			if k >= sum(l[:i + 1]) - M:
				break
		print(c, end=' ')
	else:
		print(0, end=' ')


(n, m) = list(map(int, input().split()))
t = list(map(int, input().split()))
for i in range(n):
	s = sum(t[:i])
	li = sorted(t[:i])
	res = 0
	while s > m - t[i]:
		res += 1
		s -= li[-1]
		li.pop()
	print(res, end=' ')


a = []
total = 0

def binary_search(n, l):
	first = 0
	last = len(l) - 1
	found = False
	mid = (first + last) // 2
	while first <= last and (not found):
		mid = (first + last) // 2
		if l[mid] == n:
			found = True
		elif n < l[mid]:
			last = mid - 1
		else:
			first = mid + 1
	if found:
		return mid
	else:
		return first
(n, M) = map(int, input().split())
t = [int(x) for x in input().split()]
lena = 0
for x in t:
	rem = M - x
	if rem >= total:
		print('0', end=' ')
	else:
		count = 0
		while rem > 0:
			if a[count] <= rem:
				rem -= a[count]
				count += 1
			else:
				break
		print(lena - count, end=' ')
	a.insert(binary_search(x, a), x)
	total += x
	lena += 1


(n, m) = map(int, input().split())
l = [int(i) for i in input().split()]
from math import ceil
from collections import defaultdict
freq = defaultdict(int)
sm = 0
for i in range(n):
	sm += l[i]
	cnt = 0
	if sm <= m:
		print(0, end=' ')
	else:
		rem = sm - m
		curr = 0
		cnt = 0
		for x in range(100, 0, -1):
			f = freq[x]
			if curr + f * x <= rem:
				curr += f * x
				cnt += f
			else:
				now = rem - curr
				cnt += ceil(now / x)
				curr = rem
				break
		print(cnt, end=' ')
	freq[l[i]] += 1


import math
import bisect
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = [a[0]]
sumi = a[0]
c = [0]
print(0, end=' ')
cnt = 0
for i in range(1, n):
	sumi += a[i]
	if sumi <= k:
		print(0, end=' ')
		c.append(0)
		bisect.insort(b, a[i])
	else:
		j = i - 1
		dupsum = sumi
		cnt = 0
		for l in range(j, -1, -1):
			dupsum -= b[l]
			cnt += 1
			if dupsum <= k:
				break
		print(cnt, end=' ')
		c.append(cnt)
		bisect.insort(b, a[i])


from itertools import accumulate
(n, m) = [int(el) for el in input().split()]
stud_times = [int(el) for el in input().split()]

def num_studs_to_remove(studs, save_time):
	num_studs = 0
	index = 0
	while index < len(studs):
		save_time -= studs[index]
		num_studs += 1
		index += 1
		if save_time <= 0:
			return num_studs
	return num_studs

def sol_c(times, max_time):
	cum_sums = list(accumulate(times))
	studs_to_remove = list()
	for i in range(len(times)):
		if cum_sums[i] <= max_time:
			studs_to_remove.append(0)
		else:
			time_to_save = cum_sums[i] - max_time
			studs_to_remove.append(num_studs_to_remove(sorted(times[:i], reverse=True), time_to_save))
	return ' '.join([str(el) for el in studs_to_remove])
print(sol_c(stud_times, m))


import math
import heapq
import copy
from collections import OrderedDict
from collections import deque
t = list(map(int, input().split()))
d = t[1]
k = list(map(int, input().split()))
m = []
heapq.heapify(m)
ans = list()
time = 0
for i in range(t[0]):
	time = time + k[i]
	if d - time >= 0:
		ans.append(0)
		heapq.heappush(m, -1 * k[i])
	else:
		nt = copy.copy(m)
		count = 0
		test = time
		while test > d:
			val = heapq.heappop(nt)
			val = val * -1
			test = test - val
			count = count + 1
		ans.append(count)
		heapq.heappush(m, -1 * k[i])
print(*ans)


(n, M) = map(int, input().split())
ls = list(map(int, input().split()))
for i in range(n):
	temp = sorted(ls[:i])
	Sum = ls[i]
	cnt = 1
	for j in temp:
		if Sum + j > M:
			break
		Sum += j
		cnt += 1
	print(i + 1 - cnt, end=' ')
print()


(n, m) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
ans = [0] * n
for i in range(1, n):
	(cur, remov) = (0, 0)
	b = sorted(a[:i], reverse=True)
	for j in range(len(b)):
		if m - sum(b[remov:]) >= a[i]:
			continue
		else:
			remov += 1
	ans[i] = remov
print(*ans)


(n, m) = map(int, input().split())
t = list(map(int, input().split()))
ans = [0]
summ = t[0]
for i in range(1, n):
	summ += t[i]
	if summ <= m:
		ans.append(0)
	else:
		d = summ - m
		t[:i] = list(sorted(t[:i]))
		j = i - 1
		while d > 0:
			d -= t[j]
			j -= 1
		ans.append(i - j - 1)
print(*ans)


(n, M) = list(map(int, input().split()))
t = list(map(int, input().split()))
ans = []
time_total = 0
for i in range(n):
	if t[i] <= M - time_total:
		time_total += t[i]
		ans.append(0)
	else:
		duplicate_time_total = time_total
		count = 0
		duplicate = t[:i]
		duplicate.sort(reverse=True)
		for j in duplicate:
			count += 1
			duplicate_time_total -= j
			if t[i] <= M - duplicate_time_total:
				break
		time_total += t[i]
		ans.append(count)
for i in ans:
	print(i, end=' ')


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
for x in range(a):
	if sum(c[:x + 1]) <= b:
		print(0, end=' ')
	else:
		t = 0
		p = c[:x]
		j = sum(c[:x + 1])
		p.sort(reverse=True)
		for y in range(len(p)):
			if j > b:
				j -= p[y]
				t += 1
			if j <= b:
				print(t, end=' ')
				break


(n, m) = map(int, input().split())
t = list(map(int, input().split()))
li = []
ans = []
for j in range(n):
	li = sorted(li)
	li.append(t[j])
	ruiseki = [0] * (len(li) + 1)
	for i in range(len(li)):
		ruiseki[i + 1] = ruiseki[i] + li[i]
	for i in range(len(ruiseki) - 1)[::-1]:
		if ruiseki[i] + t[j] <= m:
			ans.append(len(ruiseki) - i - 2)
			break
print(' '.join(map(str, ans)))


def array_sum(arr):
	arr_sum = 0
	for i in range(len(arr)):
		arr_sum += arr[i]
	return arr_sum
(n, M) = map(int, input().split())
t = list(map(int, input().split()))
ans = []
for i in range(n):
	t_f = t[:i]
	t_f = sorted(t_f)
	stud_count = 0
	for j in range(len(t_f)):
		if array_sum(t_f) + t[i] > M:
			t_f[-stud_count - 1] = 0
			stud_count += 1
		else:
			break
	ans.append(stud_count)
print(' '.join((str(i) for i in ans)))


import math
(a, b) = map(int, input().split())
c = list(map(int, input().split()))
j = [0] * 101
m = 0
for x in range(a):
	m += c[x]
	if m <= b:
		print(0, end=' ')
		j[100 - c[x]] += 1
	else:
		l = 0
		f = m - b
		for y in range(101):
			if j[y] != 0:
				if f <= (100 - y) * j[y]:
					if f < 100 - y:
						l += 1
						print(l, end=' ')
						break
					else:
						l += math.ceil(f / (100 - y))
						print(l, end=' ')
						break
				else:
					l += j[y]
					f -= j[y] * (100 - y)
		j[100 - c[x]] += 1


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
temp = []
data = []
for i in range(1, n):
	temp.append(arr[i - 1])
	temp.sort()
	data.append(temp[:])
ans = [0] * n
for i in range(1, n):
	time = arr[i]
	x = data[i - 1]
	count = 0
	for j in x:
		if time + j <= m:
			time = time + j
			count += 1
		else:
			break
	ans[i] = len(x) - count
print(*ans)


from collections import defaultdict
from heapq import heappop, heappush
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
prefix = [l[0]]
for i in range(1, n):
	prefix.append(prefix[-1] + l[i])
ans = []
heap = []
for i in range(n):
	if prefix[i] <= m:
		ans.append(0)
		heappush(heap, -l[i])
	else:
		count = 0
		temp = []
		total = prefix[i]
		while heap and total > m:
			z = -heappop(heap)
			temp.append(z)
			total -= z
			count += 1
		ans.append(count)
		for j in temp:
			heappush(heap, -j)
		heappush(heap, -l[i])
print(*ans)


def run():
	a = input()
	b = input()
	(n, m) = list(map(int, a.split()))
	ts = list(map(int, b.split()))
	waiting = [0]
	for i in range(1, n):
		prev = ts[0:i]
		s = sum(prev) + ts[i]
		if s <= m:
			waiting.append(0)
			continue
		prev.sort()
		temp = 0
		while True:
			del prev[-1]
			temp += 1
			if sum(prev) + ts[i] <= m:
				break
		waiting.append(temp)
	print(' '.join(list(map(str, waiting))))
run()


R = lambda : map(int, input().split())
v = []
f = []
p = s = 0
(n, m) = R()
for i in R():
	s += i
	g = s
	while s > m:
		s -= f[-1 - p]
		p += 1
	s = g
	v.append(p)
	f.append(i)
	f.sort()
	p = 0
print(*v)


import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from itertools import accumulate, combinations, permutations
from operator import add
flush = lambda : sys.stdout.flush
comb = lambda x, y: factorial(x) // factorial(y) // factorial(x - y)
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
(n, k) = r()
arr = rr()
left = k
brr = list(accumulate(arr, add))
for (i, j) in enumerate(brr):
	if j <= k:
		print(0, end=' ')
	else:
		temp = sorted(arr[:i])[::-1]
		c = 0
		for x in temp:
			j -= x
			c += 1
			if j <= k:
				break
		print(c, end=' ')


(n, M) = list(map(int, input().split()))
t = list(map(int, input().split()))
a = []
for i in range(n):
	ti = sorted(t[:i])
	Mi = M - t[i]
	s = 0
	j = 0
	while j < i:
		s += ti[j]
		if s > Mi:
			break
		j += 1
	a.append(i - j)
print(*a)


def cumsum(a):
	b = []
	b.append(a[0])
	for i in range(1, len(a)):
		b.append(a[i] + b[i - 1])
	return b
(n, m) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = cumsum(a)
c = []
for (indx, i) in enumerate(b):
	if i <= m:
		c.append(0)
	else:
		d = cumsum(sorted(a[:indx]))
		c.append(indx - len([t for t in d if t <= m - a[indx]]))
for i in c:
	print(i, end=' ')
print()


(n, time) = map(int, input().split())
clock = 0
arr = [[0, 0]]
for elem in list(map(int, input().split())):
	clock += elem
	if clock <= time:
		print(0, end=' ')
	else:
		for i in range(1, len(arr)):
			if clock - arr[i][0] <= time:
				print(i, end=' ')
				break
	found = False
	for i in range(1, len(arr)):
		if arr[i][1] < elem:
			numbf = i
			znach = arr[i][1]
			news = arr[i][0] - arr[i][1] + elem
			arr[i][0] = news
			arr[i][1] = elem
			found = True
			break
	if found:
		for i in range(numbf + 1, len(arr)):
			arr[i][0] = arr[i - 1][0] + znach
			(arr[i][1], znach) = (znach, arr[i][1])
		arr.append([arr[len(arr) - 1][0] + znach, znach])
	else:
		arr.append([arr[len(arr) - 1][0] + elem, elem])


import heapq
(n, m) = map(int, input().split())
t = [int(o) for o in input().split()]
ts = 0
h = []
lol = []
for i in range(n):
	lol = []
	ts1 = ts
	nos = 0
	while ts1 + t[i] > m:
		k = heapq.heappop(h)
		ts1 += k
		lol.append(k)
		nos += 1
	while lol:
		k = lol.pop()
		heapq.heappush(h, k)
	heapq.heappush(h, -t[i])
	ts += t[i]
	print(nos, end=' ')


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = []
ans = []
summ = 0
for i in a:
	summ += i
	sum1 = 0
	x = 0
	while summ - sum1 > m:
		sum1 += b[x]
		x += 1
	b.append(i)
	b.sort()
	b.reverse()
	ans.append(x)
print(*ans)


from sys import stdin
from collections import defaultdict, Counter
from bisect import bisect_left
from math import sqrt
from heapq import *

def iinput():
	return int(stdin.readline())

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
t = 1
while t:
	t -= 1
	(n, m) = minput()
	a = linput()
	req = 0
	heap = []
	heapify(heap)
	fail = []
	cnt = 0
	for i in range(n):
		if req + a[i] <= m:
			req += a[i]
		else:
			temp = heap.copy()
			cnt = 0
			sm = req
			while sm + a[i] > m:
				sm += heappop(temp)
				cnt += 1
			req += a[i]
		heappush(heap, -1 * a[i])
		fail.append(cnt)
	print(*fail)


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
ans = []
counted = []
s = 0
for i in arr:
	c = 0
	s += i
	temp = s
	counted.sort()
	if s > m:
		z = -1
		while temp > m:
			temp -= counted[z]
			z -= 1
			c += 1
	counted.append(i)
	ans.append(c)
print(*ans)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
a = []
ans = []
for i in range(n):
	if a == []:
		a.append(l[i])
		ans.append(0)
	else:
		s = 0
		for j in range(i):
			s += a[j]
			if s + l[i] > m:
				ans.append(i - j)
				break
		else:
			ans.append(0)
		for j in range(i):
			if l[i] < a[j]:
				a.insert(j, l[i])
				break
		else:
			a.append(l[i])
for i in ans:
	print(i, end=' ')


(n, t) = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
anss = []
for i in range(1, n + 1):
	x = sorted(l[:i - 1], reverse=True)
	o = l[i - 1]
	ans = 0
	while sum(x) + o > t and len(x) > 0:
		x.remove(max(x))
		ans += 1
	anss.append(ans)
print(*anss)


def f(t, cnt):
	cnt1 = 0
	lt = sorted(c[:t], reverse=True)
	for i in range(len(lt)):
		cnt1 += lt[i]
		if cnt1 >= cnt:
			return i + 1
			break
(a, b) = map(int, input().split())
c = input().split()
c = [int(i) for i in c]
cnt = 0
stud = 0
for i in range(len(c)):
	cnt += c[i]
	if b < cnt:
		print(f(i, cnt - b), end=' ')
	else:
		print(0, end=' ')


def insert(a, x, k):
	temp = a[x[k]]
	value = x[k]
	j = k - 1
	while j >= 0 and a[x[j]] > temp:
		x[j + 1] = x[j]
		j -= 1
	x[j + 1] = value
	return x
(n, time) = map(int, input().split())
a = list(map(int, input().split()))
rez = [0] * n
count = 0
if a[0] > time:
	count += 1
rez[0] = count
b = [0] * n
for i in range(n):
	b[i] = i
for i in range(1, n):
	t = 0
	s = a[b[i]]
	while t < i and s + a[b[t]] <= time:
		s += a[b[t]]
		t += 1
	rez[i] = i - t
	b = insert(a, b, i)
for item in rez:
	print(item, end=' ')


(n, m) = map(int, input().split())
u = list(map(int, input().split()))
u1 = []
p = 0
for i in range(n):
	p += u[i]
	u1.append(p)
ans1 = []
for i in range(n):
	if u1[i] <= m:
		ans1.append('0')
		continue
	r = u[:i]
	r.sort(reverse=1)
	x = u1[i] - m
	ans = 0
	for j in range(len(r)):
		x -= r[j]
		ans += 1
		if x <= 0:
			break
	ans1.append(str(ans))
print(' '.join(ans1))


(n, m) = list(map(int, input().split()))
l = list(map(int, input().split()))
print(0, end=' ')
i = 1
for i in range(1, n):
	lp = sorted(l[:i])
	(j, p) = (0, 1)
	sum = l[i]
	while lp[j] + sum <= m and j < i:
		sum += lp[j]
		p += 1
		j += 1
		if j >= i:
			break
	print(i - j, end=' ')


o = input().rstrip().split(' ')
p = input().rstrip().split(' ')
l = []
q = []
w = []
S = []
D = []
X = 0
for i in range(0, len(p)):
	X += int(p[i])
	if X <= int(o[1]):
		print(0, end=' ')
		l.append(int(p[i]))
	else:
		C = 0
		j = 0
		D = X
		l.sort(key=int, reverse=True)
		while j < len(l):
			C += 1
			X -= int(l[j])
			if X <= int(o[1]):
				print(C, end=' ')
				break
			else:
				j += 1
		l.append(int(p[i]))
		X = D


import bisect
tmp = input().split()
m = int(tmp[1])
ar = list(map(int, input().split()))
ar2 = list()
sum = 0
for i in ar:
	if sum + i > m:
		r = 0
		j = len(ar2) - 1
		while j >= 0 and m - sum + r < i:
			r += ar2[j]
			j -= 1
		print(len(ar2) - j - 1, end=' ')
	else:
		print(0, end=' ')
	bisect.insort(ar2, i)
	sum += i


import sys
from heapq import heappush, heappop
sys.setrecursionlimit(1000000)

class Main:

	def __init__(self):
		self.buff = None
		self.index = 0

	def next(self):
		if self.buff is None or self.index == len(self.buff):
			self.buff = self.next_line()
			self.index = 0
		val = self.buff[self.index]
		self.index += 1
		return val

	def next_line(self):
		return sys.stdin.readline().split()

	def next_ints(self):
		return [int(x) for x in sys.stdin.readline().split()]

	def next_int(self):
		return int(self.next())

	def solve(self):
		(n, m) = self.next_ints()
		t = self.next_ints()
		r = []
		s = 0
		b = 0
		h = []
		hh = []
		for v in t:
			while s + v > m:
				b += 1
				vv = -heappop(h)
				s -= vv
				heappush(hh, vv)
			r.append(b)
			heappush(hh, v)
			b += 1
			while len(hh) > 0 and s + hh[0] <= m:
				vv = heappop(hh)
				s += vv
				heappush(h, -vv)
				b -= 1
		print(' '.join((str(x) for x in r)))
Main().solve()


(n, m) = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
p = l.copy()
for i in range(1, n):
	l[i] += l[i - 1]
c = 0
s = 0
ans = []
for i in range(n):
	if l[i] > m:
		d = l[i] - m
		k = p[:i]
		k.sort(reverse=True)
		c = 0
		s = 0
		for e in k:
			if s < d:
				s += e
				c += 1
	ans.append(c)
ans = [str(x) for x in ans]
s = ' '.join(ans)
print(s)


from sys import stdout
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
dp = 0
size = max(a) + 1
b = [0] * size
for i in range(n):
	e = a[i]
	k = 1
	c = 0
	s_c = m - e
	while k < size:
		if b[k] != 0:
			if s_c < b[k] * k:
				c += s_c // k
				break
			else:
				s_c -= b[k] * k
				c += b[k]
		k += 1
	b[e] += 1
	stdout.write(str(i - c) + ' ')


(N, M) = map(int, input().split())
t = list(map(int, input().split()))
ansl = []
for i in range(N):
	a = t[i]
	d = sorted(t[:i])
	c = 0
	for j in range(i):
		a += d[j]
		c += 1
		if a > M:
			c -= 1
	ansl.append(i - c)
print(' '.join(map(str, ansl)))


R = lambda : map(int, input().split())
(n, M) = R()
L = list(R())
print(0, end=' ')
for i in range(1, n):
	su = sum(L[:i + 1])
	c = 0
	s = sorted(L[:i])
	j = i - 1
	while su > M:
		c += 1
		su -= s[j]
		j -= 1
	print(c, end=' ')


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
(n, m) = f()
l = il()
print(0, end=' ')
sm = l[0]
for i in range(1, n):
	sm += l[i]
	if sm > m:
		sm1 = 0
		c = 0
		for j in sorted(l[:i], reverse=True):
			sm1 += j
			c += 1
			if sm - sm1 <= m:
				print(c, end=' ')
				break
	else:
		print(0, end=' ')


nM = input()
(n, M) = nM.split(' ')
n = int(n)
M = int(M)
arr = input()
arr = [int(x) for x in arr.split(' ')]
ans = [str(0)] * n
s = 0
for i in range(n):
	s += arr[i]
	tmp = s - arr[i]
	if s > M:
		prev = sorted(arr[:i], reverse=True)
		k = 0
		while tmp > M - arr[i] and k < i:
			tmp -= prev[k]
			k += 1
		ans[i] = str(k)
print(' '.join(ans))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(len(a)):
	count = a[i]
	p = 0
	u = []
	for j in range(i):
		u.append(a[j])
		count += a[j]
	while count > k:
		x = max(u)
		count -= x
		u.remove(x)
		p += 1
	print(p, end=' ')


(n, m) = map(int, input().split())
arr = [int(x) for x in input().split()]
k = 0
arr2 = []
sumb = 0
for i in range(n):
	arr2.sort(reverse=True)
	suma = sumb
	tot = 0
	j = 0
	len1 = i
	while suma + arr[i] > m and j < len1:
		suma -= arr2[j]
		j += 1
		tot += 1
		if j == len1:
			break
	arr2.append(arr[i])
	sumb += arr[i]
	print(tot, end=' ')
print()


(n, M) = map(int, input().split())
print(0, end=' ')
a = [int(i) for i in input().split()]
pref = [0] * n
pref[0] = a[0]
for i in range(1, n):
	pref[i] = pref[i - 1] + a[i]
for i in range(1, n):
	now = a[:i]
	now.sort()
	k = 0
	A = M - pref[i]
	index = len(now) - 1
	while A < 0:
		A += now[index]
		index -= 1
		k += 1
	print(k, end=' ')


from heapq import *
(N, M) = map(int, input().split())
A = [int(a) for a in input().split()]
h = []
s = 0
k = 0
ANS = []
for a in A:
	t = []
	while s + a > M:
		t.append(heappop(h))
		s += t[-1]
	ANS.append(len(t) + k)
	while t:
		s -= t[-1]
		heappush(h, t.pop())
	s += a
	heappush(h, -a)
	if s > M:
		s += heappop(h)
		k += 1
print(*ANS)


(n, t) = map(int, input().split())
x = list(map(int, input().split()))
ans = []
for j1 in range(n):
	tem = []
	for i1 in range(j1):
		tem.append(x[i1])
	tem.sort()
	m = 0
	j = 0
	c = 0
	for i in range(j1):
		m += tem[i]
		c += 1
		if m > t - x[j1]:
			m -= tem[j]
			j += 1
			c -= 1
	ans.append(j1 - c)
print(*ans)


import math
import sys
(n, m) = map(int, input().split())
t = list(map(int, input().split()))
pt = [t[0]]
for i in range(1, n):
	pt.append(pt[-1] + t[i])
print(0, end=' ')
for i in range(1, n):
	if t[i] <= m - pt[i - 1]:
		print(0, end=' ')
	else:
		temp = sorted(t[:i], reverse=True)
		time = m - pt[i - 1]
		for j in range(i):
			time += temp[j]
			if t[i] <= time:
				print(j + 1, end=' ')
				break


nm = input().split()
n = int(nm[0])
m = int(nm[1])
t = input().split()
answer = []
sum_prev = 0
for i in range(n):
	sum_prev += int(t[i])
	number_removed = 0
	if sum_prev <= m:
		answer.append('0')
	else:
		t1 = list(map(int, t))
		sum_prev1 = sum_prev
		while sum_prev1 > m:
			j = i - number_removed
			sum_prev1 -= max(t1[0:j])
			t1.remove(max(t1[0:j]))
			number_removed += 1
		answer.append(str(number_removed))
print(' '.join(answer))


from sys import stdin
input = stdin.readline
(n, m) = map(int, input().split())
t = list(map(int, input().split()))
prev = m
for i in range(n):
	tmp = t[:i] + [0]
	tmp.sort()
	m = prev - t[i]
	j = 0
	while j < len(tmp) and m - tmp[j] >= 0:
		m -= tmp[j]
		j += 1
	c = len(tmp) - j
	print(c, end=' ')


(n, M) = map(int, input().split())
t = list(map(int, input().split()))
ans = []
for i in range(n):
	num = 0
	tmp = []
	T = 0
	for j in range(n):
		if i != j:
			tmp.append(t[j])
		else:
			T += t[i]
			break
	tmp = sorted(tmp)
	for j in range(len(tmp)):
		if T + tmp[j] <= M:
			T += tmp[j]
			num += 1
	ans.append(len(tmp) - num)
print(*ans)


(n, m) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
s = 0
c = 0
b = []
for i in range(n):
	s += a[i]
	y = s
	if y > m:
		c = 0
		b.sort()
		r = len(b)
		while y > m:
			y -= b[r - 1]
			c += 1
			r -= 1
	b.append(a[i])
	print(c, end=' ')


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
c = 0
for t in range(len(l)):
	c += l[t]
	if c <= m:
		print(0, end=' ')
	elif c > m:
		k = l[:t]
		k = sorted(k, reverse=True)
		x = c
		a = 0
		for i in k:
			x -= i
			a += 1
			if x <= m:
				print(a, end=' ')
				break


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
prefix_sum2 = [l[0]]
for i in range(1, n):
	prefix_sum2.append(prefix_sum2[-1] + l[i])
ans = [0]
for i in range(1, n):
	if prefix_sum2[i] <= m:
		ans.append(0)
	else:
		l1 = sorted(l[0:i], reverse=True)
		prefix_sum = [l1[0]]
		for j in range(1, len(l1)):
			prefix_sum.append(prefix_sum[-1] + l1[j])
		for j in range(len(prefix_sum)):
			if prefix_sum2[i] - prefix_sum[j] <= m:
				ans.append(j + 1)
				break
print(*ans)


(n, m) = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
s = 0
for i in range(n):
	s += t[i]
	count = 0
	if s > m:
		curr = s
		for j in sorted(t[:i], reverse=True):
			if curr > m:
				count += 1
				curr -= j
			else:
				break
	print(count, end=' ')


(n, m) = map(int, input().split())
list1 = [int(x) for x in input().split()]
sum = 0
list2 = []
for item in list1:
	list2.append(item)
	sum = sum + item
	if sum <= m:
		print(0, end=' ')
	else:
		count = 0
		sum1 = item
		for i in list2[:len(list2)]:
			sum1 = sum1 + i
			if sum1 > m:
				break
			count = count + 1
		print(len(list2) - count - 1, end=' ')
	list2.sort()


import copy
(n, m) = map(int, input().split())
T = list(map(int, input().split()))
X = [0]
s = 0
for i in T:
	s = s + i
	X.append(s)
Y = []
Z = 0
for i in range(n):
	D = X[i + 1]
	L = copy.deepcopy(T[:i])
	j = 0
	while D > m and len(L):
		Z = max(L)
		D = D - Z
		L.remove(Z)
		j = j + 1
	Y.append(j)
for i in Y:
	print(i, end=' ')


from sys import stdin, stdout

def main():
	(n, m) = stdin.readline().split()
	n = int(n)
	m = int(m)
	arr = [int(i) for i in stdin.readline().split()]
	new = [0] * n
	sum = 0
	for i in range(n):
		sum += arr[i]
		if sum <= m:
			new[i] = 0
		else:
			new_arr = arr[:i]
			new_arr = sorted(new_arr)
			count = 0
			stud = 0
			j = len(new_arr) - 1
			while j >= 0:
				count += new_arr[j]
				stud += 1
				if count >= sum - m:
					new[i] = stud
					break
				else:
					j -= 1
	s = ''
	for i in range(len(new)):
		s = s + str(new[i]) + ' '
	stdout.write(s)
main()


a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * a[0]
c[0] = b[0]
for i in range(1, a[0]):
	c[i] = c[i - 1] + b[i]
for i in range(a[0]):
	if c[i] <= a[1]:
		print(0, end=' ')
	else:
		p = 0
		j = i - 1
		s = c[i]
		k = b[:i].copy()
		k.sort()
		while j >= 0 and s > a[1]:
			s = s - k[j]
			j -= 1
			p += 1
		print(p, end=' ')


import sys, math, string
input = sys.stdin.readline
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
(n, m) = M()
l = L()
a = [0]
for i in range(1, n):
	k = l[:i]
	k.sort()
	s = l[i]
	w = 0
	for p in range(len(k)):
		if s + k[p] <= m:
			s += k[p]
			w += 1
		else:
			break
	a.append(i - w)
print(*a)


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
ans = []
for i in range(n):
	if sum(a[:i + 1]) <= m:
		ans.append(0)
		continue
	else:
		x = a[i]
		j = 1
		while True:
			b = a[:i]
			b.sort()
			if sum(b[:j]) + x <= m:
				j += 1
				continue
			else:
				y = i + 1 - j
				ans.append(y)
				break
print(' '.join((str(r) for r in ans)))


(n, time) = input().split()
n = int(n)
time = int(time)
a = input().split()
a = [int(i) for i in a]
for i in range(n):
	temp = a[:i]
	temp.sort()
	count = 0
	while sum(temp) + a[i] > time:
		temp = temp[:len(temp) - 1]
		count += 1
	print(count, end=' ')


(n, m) = [int(i) for i in input().split()]
t = [int(i) for i in input().split()]
for i in range(n):
	q = m - t[i]
	w = t[:i]
	e = sum(w)
	if e > q:
		w.sort(key=lambda x: -x)
		cnt = 0
		ind = 0
		while e > q:
			e -= w[ind]
			cnt += 1
			ind += 1
		print(cnt, end=' ')
	else:
		print(0, end=' ')


(n, M) = map(int, input().split())
T = list(map(int, input().split()))
Ans = []
for i in range(n):
	if i == 0:
		if T[i] <= M:
			Ans.append(0)
	elif i == 1:
		if T[1] + T[0] <= M:
			Ans.append(0)
		elif T[1] <= M or T[0] <= M:
			Ans.append(1)
		else:
			Ans.append(2)
	else:
		sum = 0
		for k in range(i + 1):
			sum = sum + T[k]
		if sum <= M:
			Ans.append(0)
		else:
			o = 0
			Tl = T[0:i]
			Tp = sorted(Tl, reverse=True)
			while sum > M:
				sum = sum - Tp[o]
				o = o + 1
			Ans.append(o)
print(*Ans)


(n, m) = map(int, input().split())
t = [int(e) for e in input().split()]
for i in range(n):
	notAll = False
	time = t[i]
	prev = [int(t[j]) for j in range(i)]
	prev.sort()
	for j in range(i):
		if time + prev[j] <= m:
			time += prev[j]
		else:
			notAll = True
			print(i - j, end=' ')
			break
	if notAll == False:
		print(0, end=' ')


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
add = 0
i = 0
while add < m and i < n:
	if add + l[i] <= m:
		add += l[i]
		i += 1
	else:
		break
ans = [0] * i
if i == 0:
	ans = []
for j in range(i, n):
	x = l[:j]
	x.sort(reverse=True)
	y = sum(x)
	cnt = 0
	k = 0
	while y + l[j] > m:
		y -= x[k]
		k += 1
		cnt += 1
	ans.append(cnt)
print(*ans)


import heapq
(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
s = 0
h = []
for i in range(n):
	if arr[i] + s <= m:
		print(0, end=' ')
	else:
		heapq._heapify_max(h)
		temp = []
		temp += h
		ind = 0
		temp_s = s
		while temp_s + arr[i] > m:
			temp_s -= temp[0]
			heapq._heappop_max(temp)
			ind += 1
		print(ind, end=' ')
	h.append(arr[i])
	s += arr[i]


(a, b) = input().split()
num_stud = int(a)
exam_time = int(b)
listc = list(map(int, input().split()))
result = [0 for i in range(num_stud)]
for i in range(num_stud):
	test_list = sorted(listc[0:i])
	if exam_time - sum(test_list) - listc[i] >= 0:
		result[i] = 0
	elif exam_time - sum(test_list) - listc[i] < 0:
		n = exam_time - sum(test_list) - listc[i]
		need = 0
		for j in range(1, len(test_list) + 1):
			subtract = test_list[-j:len(test_list)]
			if n + sum(subtract) >= 0:
				need += 1
				break
			elif n + sum(subtract) < 0:
				need += 1
				continue
		result[i] = need
for i in range(len(result)):
	result[i] = str(result[i])
solution = ' '.join(result)
print(solution)


from collections import Counter

def each(total, M, ocounter, student):
	counter = ocounter.copy()
	cnt = 0
	while total > M:
		m = max(counter)
		total -= m
		counter[m] -= 1
		if counter[m] <= 0:
			del counter[m]
		cnt += 1
	else:
		return cnt

def main():
	(n, M) = [int(x) for x in input().split()]
	students = [int(x) for x in input().split()]
	counter = Counter()
	result = []
	total = 0
	cnt = 0
	for student in students:
		total += student
		result.append(each(total, M, counter, student))
		counter[student] += 1
	print(' '.join([str(x) for x in result]))
main()


(n, m) = [int(x) for x in input().split()]
ti = [int(x) for x in input().split()]
op = ''
numsum = 0
for i in range(len(ti)):
	numsum = numsum + ti[i]
	if numsum <= m:
		op = op + str(0) + ' '
	else:
		nc = numsum
		subset = ti[:i]
		subset.sort()
		count = 0
		while nc > m:
			nc = nc - subset.pop()
			count += 1
		op = op + str(count) + ' '
op.rstrip()
print(op)


(n, m) = list(map(int, input().split()))
if n == 1:
	print(0)
	exit(0)
t = list(map(int, input().split()))
x = []
for i in range(len(t)):
	br = 0
	s = 0
	for j in range(len(x)):
		s += x[j]
		br = j
		if s > m - t[i]:
			break
	if s <= m - t[i]:
		print(0, end=' ')
	else:
		print(len(x) - br, end=' ')
	x.append(t[i])
	x.sort()


l = input().split()
n = int(l[0])
m = int(l[1])
l = input().split()
li = [int(i) for i in l]
print(0, end=' ')
for i in range(1, n):
	rem = m - li[i]
	z = list(li[:i])
	z.sort()
	count = 0
	for j in range(i):
		if z[j] <= rem:
			rem -= z[j]
			count += 1
		else:
			break
	print(i - count, end=' ')