Problem:


Score : 200 points

Problem Statement

There are N children, numbered 1, 2, ..., N.

Snuke has decided to distribute x sweets among them.
He needs to give out all the x sweets, but some of the children may get zero sweets.

For each i (1 \leq i \leq N), Child i will be happy if he/she gets exactly a_i sweets.
Snuke is trying to maximize the number of happy children by optimally distributing the sweets.
Find the maximum possible number of happy children.

Constraints

All values in input are integers.

2 \leq N \leq 100

1 \leq x \leq 10^9

1 \leq a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N x
a_1 a_2 ... a_N

Output

Print the maximum possible number of happy children.

Sample Input 1

3 70
20 30 10

Sample Output 1

2

One optimal way to distribute sweets is (20, 30, 20).

Sample Input 2

3 10
20 30 10

Sample Output 2

1

The optimal way to distribute sweets is (0, 0, 10).

Sample Input 3

4 1111
1 10 100 1000

Sample Output 3

4

The optimal way to distribute sweets is (1, 10, 100, 1000).

Sample Input 4

2 10
20 20

Sample Output 4

0

No children will be happy, no matter how the sweets are distributed.



Sample input:
3 70
20 30 10


Sample output:
2

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=a[0]
y=a[1]
b.sort()
i=0
k=0
while i ==0:
	t=b[0]
	if y>=t:
		k=k+1
		y=y-t
		del b[0]
	else:
		i=1
	if x==k:
		i=1
if y>0 and x==k:
	k=k-1
print(k)

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,x = map(int,input().split())
a = map(int,input().split())
ret = 0
for i,n in enumerate(sorted(a)):
  if i == N-1 and n == x:
    x -= n
    ret += 1
  elif i < N-1 and n <= x:
    x -= n
    ret += 1
  else:
    break
print(ret)

Submission status: Accepted

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

#print(N, x)
A.sort()
#print(A)

cnt = 0
for a in A:
  if x >= a:
    x -= a
    cnt += 1
  
  else:
    break

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

N, x = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
a.sort()
ans = 0
for i, ai in enumerate(a):
    x -= ai
    if (x > 0 and i != len(a)-1) or x == 0:
        ans += 1
    else:
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, candy = list(map(int, input().split()))
nums = list(map(int, input().split()))

nums.sort()

ans = 0
for i in range(n):
    if candy >= nums[i]:
        candy -= nums[i]
        ans += 1
    else:
        break

# 配りきってまだ余っている場合
if candy > 0 and ans == n:
    ans -= 1
print(ans)

Submission status: Accepted

Solution code:
import math
N,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
#print(a)
conf=0
for i in range(N):
    if i==N-1:
        if a[i]==x:
            conf=conf+1
    else:
        if a[i]<=x:
            conf=conf+1
            x=x-a[i]
        else:
            break
print(conf)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
A_list = list(map(int, input().split()))
A_list = sorted(A_list)
for i in range(N):
    x -= A_list[i]
    if x <= 0:
        break
print(i+1) if x == 0 else print(i)

Submission status: Accepted

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

Submission status: Accepted

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

A.sort()

required = sum(A)
# 飴が余るか足りないか
if required == x:
    ans = N
elif required < x:  # 雨の数は足りている
    ans = N - 1
else:  # 飴が足りていない
    sm = 0
    ans = 0
    for ai in A:
        sm += ai
        if sm <= x:
            ans += 1
        else:
            break

print(ans)

Submission status: Accepted

Solution code:
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = [int(input()) for i in range(n)]
    #a = list(map(int, input().split()))
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    n,x=map(int,input().split())
    a=sorted(map(int,input().split()))
    cnt = 0
    suma = sum(a)
    if suma < x:
        print(n-1)
    elif suma == x:
        print(n)
    else:
        for i in a:
            if x < i:
                break
            cnt+=1
            x-= i
        print(cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
N, x = map(int, input().split())
a = sorted(map(int, input().split()))


ans = 0
score_x  = x

if score_x < a[0]:
    print(0)
    sys.exit()
    
for  i in range(N):
    if i == (N-1):
        if a[i] == score_x:
            ans = ans + 1
            score_x = (score_x - a[i])
        else:
            break      
    if score_x  >= a[i]:
        score_x = (score_x - a[i])
        ans = ans + 1


print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate
from bisect import bisect
N,x,*A=map(int, open(0).read().split())
B=list(accumulate(sorted(A)))
i=bisect(B, x)
if i==N and sum(A)!=x:
    i=N-1
print(i)

Submission status: Accepted

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

ss = list(map(int, input().split(' ')))
    
r = x
count = 0    
for s in sorted(ss):
    if r - s < 0:
        break
    else:
        n -= 1
        r -= s
        count += 1
if r > 0 and n <= 0:
    count -= 1
print(count)

Submission status: Accepted

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

answer = 0
id = -1

for idx, a in enumerate(sorted(li_a)):
    if x >= a:
        answer += 1
        x -= a
        id = idx
    else:
        break
if answer == 0:
    print(answer)
elif x == 0:
    print(answer)
else:
    if id == (n -1):
        print(answer - 1)
    else:
        print(answer)

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
res = 0
dat = list(map(int, input().split()))

dat.sort()

for i in range(n):
    if x >= dat[i]:
        res += 1
        x -= dat[i]
    else:
        break
if x != 0 and res != 0 and res == n:
    res -= 1
print(res)

Submission status: Accepted

Solution code:
N,x=[int(i) for i in input().split()]
a = [int(x) for x in input().split()]
a.sort()
cnt=0
for k in a:
	x -= k
	if x < 0:
		break
	cnt +=1
if x >0:
	cnt -=1
print(cnt)

Submission status: Accepted

Solution code:
N,n=map(int,input().split())
A=list(map(int,input().split()))
A.sort()

ans=0
i=0
while A[i]<=n:
  if i==N-1:
    if n==A[i]:
      ans+=1
    break
  else:
    ans+=1
    n-=A[i]
    i+=1  
print(ans)

Submission status: Accepted

Solution code:
N,x=map(int,input().split())
A=sorted(list(map(int,input().split())))
a=[0]*N
a[0]=A[0]
for i in range(N-1):
    a[i+1]=a[i]+A[i+1]
ans=0
for i in a:
    if i<=x:
        ans+=1
print(ans if x<=a[-1] else ans-1)

Submission status: Accepted

Solution code:
import itertools

def main():
    N,x = map(int,input().split())
    a = sorted(list(map(int,input().split())))
    accum_a = list(itertools.accumulate(a))
    ans = 0
    for i in range(N):
        if accum_a[i] > x:
            break
        else:
            ans += 1
    if accum_a[-1] < x:
        ans -= 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


#----------
n,x = list(map(int, input().rstrip().split()))
a_list = list(map(int, input().rstrip().split()))
#----------
a_list.sort()
x_remain=x

result = -1
for i in range(n):
    x_remain -= a_list[i]
    
    if x_remain == 0:
        result = i+1
        break
    if x_remain < 0:
        result = i
        break

if result == -1 :
    result = n-1

print(result)

Submission status: Accepted

Solution code:
N, x = map(int,input().split())
a = list(map(int,input().split()))
count = 0
a_new = sorted(a)

for i in range(0, N):
	count += a_new[i]
	if x == count:
		index = i + 1
		break
	if count > x:
		index = i
		break
	index = i

print(str(index))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def main():
    N, x = map(int, input().split())
    a_list = list(map(int, input().split()))
    ans = 0
    for a in sorted(a_list):
        if a <= x:
            ans += 1
            x -= a
        else:
            break
    if x == 0 or ans != N:
        print(ans)
    else:
        print(max(ans - 1, 0))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

list_a.sort()
total = sum(list_a)
if x < list_a[0] :
    print(0)
    exit()
if x > total :
    print(len(list_a)-1)
    exit()
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
[N, x] = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
count = 0
i = 0
while x > 0 and i <= len(a):
  x -= a[i]
  if i == len(a)-1:
    if x != 0:
      break
  if x >= 0:
    count += 1
  i += 1
  
print(count)

Submission status: Accepted

Solution code:
from itertools import accumulate
import bisect
N,x = map(int,input().split())
A = sorted(list(map(int,input().split())))
A = list(accumulate(A))
ind = bisect.bisect_right(A,x)-1
if ind == -1:
    print(0)
elif ind == N-1:
    if A[ind] == x:
        print(ind+1)
    else:
        print(ind)
else:
    print(ind+1)

Submission status: Accepted

Solution code:
N, x = [int(i) for i in input().split(" ")]
lst = [int(i) for i in input().split(" ")]
 
lst.sort()
cnt = 0
 
for i in range(0,N-1):
  if x >= lst[i]:
    x -= lst[i]
    cnt += 1
  else:
    break

    
print(cnt+(x==lst[N-1]))

Submission status: Accepted

Solution code:
N, x = [int(i) for i in input().split(" ")]
lst = [int(i) for i in input().split(" ")]
 
lst.sort()
cnt = 0
 
for i in range(0,N-1):
  if x >= lst[i]:
    x -= lst[i]
    cnt += 1
  else:
    break

if x == lst[N-1]:
    cnt +=1
    
print(cnt)

Submission status: Accepted

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

a.sort()

cnt = 0
for val in a[:-1]:
    x -= val
    if x < 0:
        break
    cnt += 1
if x == a[-1]:
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
a = [int(_) for _ in input().split()]
a.sort()
ans = 0
for i in a:
    if x < i:
        break
    x -= i
    ans += 1
if ans == n:
    if x > 0:
        ans -= 1
print(ans)

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
aList = list(map(int, input().split()))
aList.sort()
sums = 0
i = 0
while sums < x and i < n:
    sums += aList[i]
    i += 1
i -= 1
if sums == x:
    i += 1
print(i)

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
a = sorted([int(i) for i in input().split()])
ans = 0

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


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

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
s_a = sorted(a)
cnt = 0

for i in range(N-1):
    if(s_a[i] <= x):
        cnt += 1
        x -= s_a[i]
if(s_a[N-1] - x == 0):
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
try:
  N, x = map(int, input().split())
  a = list(map(int, input().split()))
  a_ = sorted(a)
  cnt = 0
  for i in range(len(a_)-1):
      if a_[i]<=x:
          cnt += 1
          x = x-a_[i]
  if a_[len(a_)-1]-x==0:
      cnt += 1
  print(cnt)
except EOFError:
  pass

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
array = list(map(int, input().split()))
a = sorted(array, reverse=False)
#print(a)
answer = 0
for i in range(N):
    x -= a[i]
    if x < 0:
        break
    answer += 1
    if i == N-1 and x != 0:
        answer -= 1
        break
    if x < a[i]:
        break
print(answer)

Submission status: Accepted

Solution code:
N, x = [int(z) for z in input().split()]
children = [int(z) for z in input().split()]

children.sort()
sum = 0

for i in children:
    sum += i

if sum < x:
    print(N - 1)
#elif sum == x:
#    print(N)
else:
    cnt = 0
    for i in children:
        if x - i < 0:
            break
        else:
            x -= i
            cnt += 1
    print(cnt)

Submission status: Accepted

Solution code:
N, x = [int(z) for z in input().split()]
children = [int(z) for z in input().split()]

children.sort()
sum = 0

for i in children:
    sum += i

if sum < x:
    print(N - 1)
elif sum == x:
    print(N)
else:
    cnt = 0
    for i in children:
        if x - i < 0:
            break
        else:
            x -= i
            cnt += 1
    print(cnt)

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
L = list(map(int,input().split()))
L_sorted = sorted(L, reverse=False)

remain = x
ans = 0
for j in range(N):
    if remain>= L_sorted[j] and j != N-1:
        remain = remain - L_sorted[j]
        ans += 1
    
    if j == N-1 and L_sorted[j] == remain:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

A.sort()
c = 0
for i in A:
    x -= i
    if x >= 0:
        c += 1
    else:
        break

if x > 0:
    c -= 1

print(c)

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
if sum(a) == x:
    print(n)
elif sum(a) < x:
    print(n-1)
else:
    a = sorted(a)
    total = 0
    for i in range(n):
        total += a[i]
        if total == x:
            print(i+1)
            exit()
        elif total > x:
            print(i)
            exit()

Submission status: Accepted

Solution code:
def solve(n, x, A):
    A.sort()
    count = 0
    for i in range(n):
        if i < n - 1 and A[i] <= x or i == n - 1 and A[i] == x:
            x -= A[i]
            count += 1
        else:
            break
    return count

_n, _x = list(map(int, input().split()))
_A = list(map(int, input().split()))
print(solve(_n, _x, _A))

Submission status: Accepted

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

if sum(A) < x:
    print(N-1)
else:
    A.sort()
    count = 0
    while(x > 0):
        x -= A[count]
        if x >= 0:
            count += 1
    print(count)
    
# 子供が喜ぶお菓子の合計sum(A)が配れるお菓子の数xより大きいか否かで場合分け
# sum(A) < x　のとき子供全員にお菓子は配れるが、余りが発生するので一人は喜ばない

Submission status: Accepted

Solution code:
N, x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
f=0
i=0
while x>=a[i]:
    x=x-a[i]
    i=i+1
    f=f+1
    if i==N:
        break
if i==N and x>0:
    print(f-1)
else:
    print(f)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
array = list(map(int, input().split()))
a = sorted(array, reverse=False)
#print(a)
answer = 0
for i in range(N):
    x -= a[i]
    if x < 0:
        break
    answer += 1
    if i == N-1 and x != 0:
        answer -= 1
        break
    if x < a[i]:
        break
print(answer)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

#n, a, b= map(int, input().split())
n, x  = map(int, input().split())
a = list(map(int, input().split()))
#s = list(str(input()))
#n = int(input())

#a = [""]*n
#for i in range(n):
#  a[i] = str(input())

#for i in range(n):
a.sort()
tot = 0
for i in range(n):
  tot = tot + a[i]
  if(x < tot):
    print(i)
    break

if(x == tot):
  print(i+1)
if(x > tot):
  print(i)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def getInput():
    return [int(i) for i in input().rstrip().split(' ')]

N, x = getInput()
a_i = getInput()
a_i.sort()
child = 0
for i in range(N):
    a = a_i.pop(0)
    if x >= a:
        x = x - a
        if x > 0 and not a_i:
            break
        child += 1
    if x == 0:
        break

print(child)

Submission status: Accepted

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

Submission status: Accepted

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

A = sorted(a)

ans = 0

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

Submission status: Accepted

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

a.sort()
tmp = a[0]
cnt = 0
for i in range(1,n):
    #print(cnt,tmp)
    if tmp<=x:
        cnt += 1
        tmp += a[i]
    else:
        break
if tmp==x:
    cnt +=1
print(cnt)

Submission status: Accepted

Solution code:
from sys import stdin

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))
li.sort()
count = 0
for i in range(n-1):
    if li[i] <= m:
        count += 1
        m -= li[i]
if li[-1] == m:
    count += 1
print(count)

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
a_list = list(map(int, input().split()))

#%%
ans = 0
a_list.sort()

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

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

print(ans)

Submission status: Accepted

Solution code:
import itertools
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
a = list(itertools.accumulate(a))
cnt = 0
for i in range(n):
    if i==n-1 and a[-1]!=x:
        pass
    elif a[i]<=x:
        cnt+=1
print(cnt)

Submission status: Accepted

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

lista.sort()

snack = 0

for i in range(n):
  if lista[i] + snack <= x:
    snack += lista[i]
  else:
    print(i)
    break
else:
  if snack == x:
    print(n)
  else:
    print(n - 1)

Submission status: Accepted

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

Submission status: Accepted

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

# 小さい数から配っていくと子供の人数を最大化できる
a = sorted(a)

leftCandy = x
childrenCnt = 0
for i in range(len(a)):
  leftCandy -= a[i]
  if leftCandy >= 0:
    childrenCnt += 1

if leftCandy > 0:
  childrenCnt -= 1

print(childrenCnt)

Submission status: Accepted

Solution code:
N,x = map(int,input().split())
li = list(map(int,input().split()))

newLi = sorted(li)
ans = 0

for i in range(len(newLi)):
  if x - newLi[i] < 0:
    break
   
  if i == (len(newLi) - 1) and x != newLi[i]:
    break
  
  x -= newLi[i]
  ans += 1

print(ans)

Submission status: Accepted

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

a.sort()

rem = x
give = 0

for i in range(n):
    rem -= a[i]
    give += 1
    if rem < 0:
        break

if rem != 0:
    give -= 1

print(give)

Submission status: Accepted

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

ans = 0
m = x

ls.sort()

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

if m > sum(ls):
    print(ans - 1)
else:
    print(ans)

Submission status: Accepted

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

cont = 0

for i in sorted(a):
    x -= i
    if x >= 0:
        cont += 1
    else:
        break

if x > 0:
    cont -= 1

print(cont)

Submission status: Accepted

Solution code:
N,x = map(int,input().split())
A = sorted(list(map(int,input().split())))
cnt = 0
tot = A[0]
while cnt<N and tot<=x:
    cnt += 1
    if cnt<N:
        tot += A[cnt]
if cnt==N and tot<x:
    cnt -= 1
print(cnt)

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n, x = LI()
    a = LI()
    a.sort()
    ans = 0
    for ai in a:
        x -= ai
        if x < 0:
            print(ans)
            return
        ans += 1
    print(ans - (x != 0))
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

al = sorted(al)
for idx, a in enumerate(al):
   if x >= a:
      x -= a
   else:
      print(idx)
      import sys
      sys.exit()
if x > 0:
   print(n-1)
else:
   print(n)

Submission status: Accepted

Solution code:
from itertools import accumulate
from bisect import bisect_right

N, x, *A = map(int, open(0).read().split())

A.sort()
S = list(accumulate(A))

if S[-1] == x:
    print(N)
else:
    print(min(N - 1, bisect_right(S, x)))

Submission status: Accepted

Solution code:
from itertools import accumulate
from bisect import bisect_right

N, x, *A = map(int, open(0).read().split())

A.sort()
S = list(accumulate(A))

if S[-1] == x:
    print(N)
else:
    k = bisect_right(S, x)
    print(N - 1 if k == N else k)

Submission status: Accepted

Solution code:
from sys import stdin, exit
import itertools
#stdin = open("input.txt")

if __name__ == "__main__":
    N, K = [int(item) for item in stdin.readline().split()]
    li = [int(item) for item in stdin.readline().split()]
    
    li.sort()
    
    if sum(li) == K:
        print(N)
    elif sum(li) < K:
        print(N-1)
    else:
        cumsum = itertools.accumulate(li)
        index = [i for i, item in enumerate(cumsum) if item<=K]
        print(len(index))

Submission status: Accepted

Solution code:
#A - Candy Distribution Again
N,x = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)

tmp = 0
A_1  = x
for i in range(N):
    A_1 = A_1 - a[i]
    if A_1 > 0:
        if i == N-1:
            print(tmp)
            exit()
        else:
            tmp += 1
    elif A_1 == 0:
        tmp += 1
        print(tmp)
        exit()

    else:
        print(tmp)
        exit()
print(tmp)

Submission status: Accepted

Solution code:
n,x=map(int, input().split())
l=sorted(list(map(int, input().split())))
ans=0
if x==sum(l):
  print(n)
elif x>sum(l):
  print(n-1)
else:
  for i in range(n):
    if x>=l[i]:
      ans+=1
      x=x-l[i]
    else:
      print(ans)
      exit()

Submission status: Accepted

Solution code:
import sys
import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, x = rl()
A = rl()
A.sort()
A = np.array(A)
A_cum = A.cumsum()
answer = 0
if A_cum[-1] < x:
    answer = N - 1
for i in range(N):
    if A_cum[i] == x:
        answer = i+1
        break
    elif A_cum[i] > x:
        answer = i
        break
        
print(answer)
# 48

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from bisect import bisect_right
import itertools

N,X,*A = map(int,read().split())

A.sort()
Acum = list(itertools.accumulate(A))

answer = bisect_right(Acum,X)
if answer == N:
    if Acum[-1] < X:
        answer -= 1
print(answer)

Submission status: Accepted

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

a.sort()
cnt=0
for i in range(N):
    if i==N-1:
        if x==a[i]:
            cnt+=1
    elif x>=a[i]:
        x=x-a[i]
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
N, x = map(int,input().split())
a = [int(_) for _ in input().split()]
s = sum(a)
a.sort()
cnt = 0
for i in range(N):
    if x >= a[i]:
        cnt += 1
        x -= a[i]
    elif x > 0:
        x -= max(x,a[i])
if x > 0:
    cnt -= 1
print(cnt)

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
if a[0]>x:
    print(0)
    exit()
cnt=1
for i in range(1,n):
    a[i]+=a[i-1]
    if a[i]>x:
        break
    cnt+=1
if cnt==n and a[-1]!=x:
    cnt-=1
print(cnt)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, x =  map(int, input().split(' '))
A = list(map(int, input().split(' ')))
A.sort()

n, ans = 0, 0
for i in range(N):
    if n + A[i] <= x:
        n += A[i]
        ans += 1
    else:
        break

if n < x and ans == N:
    print(ans - 1)
else:
    print(ans)

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
if a[0]>x:
    print(0)
    exit()
cnt=1
for i in range(1,n):
    a[i]+=a[i-1]
    if a[i]>x:
        break
    cnt+=1
if cnt==n and a[-1]!=x:
    cnt-=1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

count = 0
for i, a in enumerate(sorted(A)):
    if X >= a:
        count += 1
        X -= a

if count == N and X > 0:
    count -= 1

print(count)

Submission status: Accepted

Solution code:
N, x = list(map(int, input().split()))
li = sorted(list(map(int, input().split())))
res = 0
for i  in li:
    x -= i
    if x < 0:
        break
    else:
        res += 1
if x > 0:
    res -= 1

print(res)

Submission status: Accepted

Solution code:
A,B = map(int,input().split())
X =list(map(int,input().split()))
X = sorted(X)
count = 0
j=len(X)
if B == sum(X):
  print(len(X))
else:
  for i in range(A):
    a = X.pop(0)
    B=B - a
    if B >= 0:
      count += 1
    if B >= 0 and count == j:
      count = count -1
  print(count)

Submission status: Accepted

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

if sum(a) == x :
  print(N)
else :
  a.sort()
  s = 0
  for i in range(N) :
    if s + a[i] > x :
      break
    s += a[i]

  print(i)

Submission status: Accepted

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

a.sort()
ans = 0

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

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