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()))

l = sorted(a)
flag = False
for i in range(n):
    x -= l[i]
    if x < 0:
        flag = True
        break
if flag:
    print(i)
elif x == 0:
    print(n)
elif x > 0:
    print(n - 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[17]:


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


# In[18]:


a_sum = sum(a)
if a_sum == x:
    print(N)
elif a_sum < x:
    print(N-1)
else:
    for i in range(N):
        if x < sum(sorted(a, reverse=False)[:i+1]):
            print(i)
            break


# In[ ]:

Submission status: Accepted

Solution code:
n,x,*a=map(int, open(0).read().split())
a.sort()
for i in range(n):
    x-=a[i]
    if x<0:
      print(i)
      exit()
    elif x==0:
      print(-~i)
      exit()
print(n-1)

Submission status: Accepted

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

a_sort = sorted(a)
ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


from bisect import bisect_right
import itertools


def solve(N: int, x: int, a: "List[int]"):
    a.sort()
    acum = list(itertools.accumulate(a))
    ans = bisect_right(acum, x)
    if ans == N and acum[-1] < x:
        ans -= 1
    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, x, a)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    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]
            ans += 1
        else:
            break

    if ans == N and x > 0:
        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()))
A.sort()
for i in range(len(A)):
  if x-A[i]<0:
    print(i)
    exit()
  else:
    x-=A[i]
if x==0:print(N)
else:print(N-1)

Submission status: Accepted

Solution code:
N, x = [int(x) for x in input().strip().split()]
an = sorted([int(a) for a in input().strip().split()])
cumsum = 0
ans = 0
for i, a in enumerate(an, start=1):
  cumsum += a
  if cumsum > x:
    break
  ans = i
else:
  if cumsum != x:
    ans -= 1
print(ans)

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans, cur = 0, 0
if(sum(a) <= x):
    if(sum(a) != x): N -= 1
    print(N)
    exit(0)

for i in range(N):
    cur += a[i]
    if(cur > x): break
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
an = list(map(int, input().split()))
an.sort()
ans = 0
for a in an:
    x -= a
    if x < 0:
        break
    ans += 1
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()
ans = 0
f = 0
for i in range(n):
    if x-a[i]>=0:
        ans+=1
        x-=a[i]
    else:
        f = 1
        break
if x>0 and f==0:
    ans-=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
A = map(int, input().split())
#A = sorted(A, reverse=True)
A = sorted(A)

tmp = 0
count = 0
for i, a in enumerate(A):
    if tmp + a > x:
        break
    if (i == len(A) -1) and tmp + a < x:
        break
    tmp += a
    count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

A = sum(a)
if x > A:
    print(N-1)
elif x == A:
    print(N)
else:
    t = 0
    for n in range(N):
        t += a[n]
        if t > x:
            print(n)
            break

Submission status: Accepted

Solution code:

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

A.sort()
ans = []
for i in A:
	x -= i
	#print(ans, x)
	if x >= 0:
		ans.append(i)
	else:
		break
	
if x > 0:
	print(len(ans)-1)
else:
	print(len(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:
    x -= a
    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()

current = x
result = 0

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

if result == N and current > 0:
    result -= 1

print(result)

Submission status: Accepted

Solution code:
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
result = 0
sorted_a = sorted(a)
remain = x
for a_i in sorted_a:
    if remain >= a_i:
        result += 1
        remain -= a_i
    else:
        break

### 最後の子供にぴったりのお菓子をあげられなかった
if result == N and remain != 0:
    result -= 1
print(result)

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
al = list(map(int,input().split()))
al.sort()
c = 0
for a in al:
  if x >= a:
    c += 1
  x -= a
if x > 0 and c > 0:
  c -= 1
print(c)

Submission status: Accepted

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

for i in a:
  if x - i >= 0:
    x -= i
    count += 1
if x > 0 and count != 0  and p > sum(a):
  count -= 1
print(count)

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

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

print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

sum = 0
count = 0
for i in a[:-1]:
  sum+=i
  if sum>k:
    break
  count+=1
if a[-1]==k-sum:
  count+=1
print(count)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
A = sorted(list(map(int, input().split())))
count = 0
for i in range(n - 1):
	if A[i] <= x:
		x -= A[i]
		count += 1
	else:
		print(count)
		exit()
print(count if x != A[n - 1] else count + 1)

Submission status: Accepted

Solution code:
#Candy Distribution Again
n,x = map(int, input().split())
s= list(map(int,input().split()))

s.sort()
s.reverse
ans=0
if s[0]>x:
    print(ans)
else :
    for i in s:
        x=x-i
        if x>=0:
            ans+=1
        else :
            break
    if x>0:
        ans-=1
    print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_right
import itertools

N, x = map(int, input().split())
a = list(map(int, input().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
sum_x = 0
for i in range(N):
  if(i == N-1):
    if((x-sum_x) == A[N-1]):
      cnt += 1
    break
  
  if(sum_x+A[i] <= x):
    sum_x += A[i]
    cnt += 1
  else:
    break
   
    
print(cnt)

Submission status: Accepted

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

for i, v in enumerate(a):
    x -= v
    if x < 0:
        ans = i
        break
    if x == 0:
        ans = i + 1
        break
    if i == N - 1: 
        ans = i + 1
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()
ans = 0
for i, v in enumerate(a):
    x -= v
    if x < 0:
        ans = i
        break
    if x == 0:
        ans = i+1
        break
    if i == n-1:
        ans = i+1
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)

count = 0

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

if a[-1] == x:
    count += 1

print(count)

Submission status: Accepted

Solution code:
n,x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
count = 0
while True:
    if count > n-1:
        if x == a[n-1]:
            print(count)
            exit()
        else:
            print(count-1)
            exit()
    if a[count] < x:
        x-=a[count]
        count += 1
    elif a[count] == x:
        print(count+1)
        exit()
    else:
        print(count)
        exit()

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

Submission status: Accepted

Solution code:
def main():
    n, x = map(int, input().split())
    num_list = list(map(int, input().split()))

    ans = 0
    num_list.sort()

    for num in num_list:
        if x - num >= 0:
            x -= num
            ans += 1
        else:
            break

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
total=sum(a)
#おかしが余る場合
if total<x:
  print(N-1)
#配りきれる場合
elif total==x:
  print(N)
#子供が余る場合
else:
  ans=0
  d=[0]*N
  for i in range(N):
    if x>=a[i]:
      x-=a[i]
      d[i]=1
  ans=d.count(1)
  print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from bisect import bisect_left
from itertools import accumulate


N, x = map(int, input().split())
a = list(accumulate(sorted(map(int, input().split()))))
if x in a:
    print(bisect_left(a, x) + 1)
else:
    pos = bisect_left(a, x)
    print(N - 1) if pos == N else print(pos)

Submission status: Accepted

Solution code:
n,x = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
cnt=0
for i,X in enumerate(a):
    if x>=X:
        cnt+=1
        x-=X
    else:
        break
if cnt==n and x>0:
    cnt-=1
print(cnt)

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
l = sorted(list(map(int,input().split())))
pe = 0
for i in l:
  if x-i>=0:
    x -= i
    pe += 1
  else:
    break
if x!=0 and n==pe:
  print(pe-1)
else:
  print(pe)

Submission status: Accepted

Solution code:
from itertools import accumulate
import bisect
N, x = map(int, input().split())
a = sorted(list(map(int, input().split())))
c = list(accumulate(a))
ans = bisect.bisect_right(c, x)
if not ans:
  print(ans)
else:
  print(ans if c[N - 1] >= x else ans - 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
tmp=x
ans=0
for i in a[:-1]:
    tmp=tmp-i
    if tmp>=0:
        ans+=1
if tmp==a[-1]:
    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
bit = 0
for i in range(n):
    if a[i] <= x:
        x -= a[i]
        ans += 1
    else:
        bit = 1
if x != 0 and bit == 0:
    ans = max(0, ans - 1)
print(ans)

Submission status: Accepted

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

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

    if ans == n:
        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
while x>0 and a:
    c = a.pop(0)
    if x>=c:
        ans +=1
    x-=c
if x>0:
    ans-=1
print(ans)

Submission status: Accepted

Solution code:
N, X = map(int, input().split())
a = list(map(int, input().split()))
ans = 0

if X == min(a):
  print(1)
elif X == sum(a):
  print(len(a))
else:
  while X > 0 and N > 0:
    X -= min(a)
    N -= 1
    a.remove(min(a))
    ans += 1
  print(ans - 1)

Submission status: Accepted

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

Submission status: Accepted

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

a.sort()
if x == sum(a):
    print(n)
elif x > sum(a):
    print(n-1)
else:
    for i in range(n):
        if x < a[i]:
            print(i)
            break
        x -= a[i]

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
n,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
ans = 0
for i in range(n):
	if x-a[i] >= 0 and i != n-1:
		x = x-a[i]
		ans += 1
	elif i == n-1:
		if x-a[i]==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.sort()
count = 0
for i in range(n):
    x = x - a_list[i]
    count += 1
    if x <= 0:
        break


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

Submission status: Accepted

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


def read():
    N, x = map(int, input().strip().split())
    A = map(int, input().strip().split())
    return N, x, A


def solve(N, x, A):
    count = 0
    for a in sorted(A):
        x -= a
        if x < 0:
            break
        count += 1
    if x > 0:
        count -= 1
    return max(count, 0)


if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Submission status: Accepted

Solution code:
from itertools import accumulate
from operator import add

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

if sum(A) == x:
    print(N)
else:
    t = len(list(filter(lambda y: y <= x, accumulate(A, func=add))))
    if t == N:
        print(N - 1)
    else:
        print(t)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007
INF = 122337203685477580

def solve():
    N,x = map(int, input().split())
    vec =list(map(int, input().split())) 
    vec.sort()
    SUM = 0
    i = 0
    for p in range(N):
        SUM += vec[p]


        # print(SUM)
        if(SUM > x):
            break
        
        i += 1

    if(x > sum(vec)):
        i -= 1
    print(i)
        
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import math


# For taking integer inputs.
def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


N, x = invr()

a = inlist()
a = sorted(a)
c = 0
for i in a:
    if i <= x:
        c += 1
        x -= i
    else:
        x = 0

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

Submission status: Accepted

Solution code:
N,X = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a)
m = sum(a)
count = 0
S=0
if m == X:
    print(N)
elif m < X:
    print(N-1)
elif a[0] > X:
    print(0)
else: 
    for i in a:
        if S <= X:
            S = S + i
            count = count + 1
    else:
        print(count-1)

Submission status: Accepted

Solution code:
def last_alert(list_):
    iter_ = iter(list_)
    n = next(iter_)
    for i in iter_:
        yield n, False
        n = i
    yield n, True


N, X = map(int, input().split())
ans = 0
for i, is_last in last_alert(sorted(map(int, input().split()))):
    if is_last and X != i:
        break
    elif X < i:
        break
    X -= i
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math
from collections import deque
from collections import defaultdict

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq

n,x = readInts()
a = readInts()
a.sort()
ans = []

if a[0]>x:
	print(0)
	exit()
elif sum(a)<x:
	print(len(a)-1)
	exit()

for i in range(1,len(a)+1):
	if sum(a[:i])<=x:
		ans = a[:i]
	else:
		break


print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

c = 0
p = x

for i in range(n-1):
    if a[i] > p:
        print(c)
        sys.exit()
    else:
        c += 1
        p -= a[i]

if a[-1] == p:
    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()
ans = 0

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

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def SS(): return map(str,sys.stdin.readline().rstrip().split())
def II(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

N,x = II()
a = LI()
a.sort()
cnt = 0
for ai in a:
  if x > ai:
    x -= ai
    cnt += 1
  elif x == ai:
    cnt += 1
    x -= ai
    break
  else:
    cnt += 1
    break
if x != 0:
  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 i in a:
    x-=i
    if x>=0:
        cnt+=1

if x>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
for i in range(N):
  x = x-a[i]
  if x>=0:
    ans+=1
  else:
    break
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()))
a.sort()
cnt=0
if sum(a) < x:
    print(n-1)
    exit()
for i in range(n):
    if x>=a[i]:
        cnt+=1
        x-=a[i]
    else:
        break
print(cnt)

Submission status: Accepted

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

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

a.sort()

sweets=0

ans = 0

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

if sweets < x:
    print(ans-1)
else:
    print(ans)

Submission status: Accepted

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

a.sort()
flg = True
cnt = 0

if sum(a) < x:
  cnt = n - 1
  flg = False
  
while flg:
  for i in range(n):
    if a[i] <= x:
      cnt += 1
      x -= a[i]
    else:
      flg = False
print(cnt)

Submission status: Accepted

Solution code:
N,x = [int(hoge) for hoge in input().split()]
A = [int(hoge) for hoge in input().split()]
#x個のお菓子を配る。
#和がxを越えないように最も多い数のaを選ぶ
A.sort()
ans = 0
cur = 0
for a in A:
    cur += a
    if cur > x:
        print(ans)
        exit()
    ans += 1
if cur == x:print(N)
else:print(ans-1)

Submission status: Accepted

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

Submission status: Accepted

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

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

if x >0:
    print(n-1)
elif x==0:
    print(n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# A - Candy Distribution Again

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

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

print(ans)

Submission status: Accepted

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

ans = 0
for i in range(len(a)):
    if not i == len(a)-1:
        if x > a[i]:
            ans += 1
            x = x-a[i]
        elif x == a[i]:
            ans += 1
            break
        else: #x < a[i]
            break
    else:
        if x == a[i]:
            ans += 1
        else:
            pass

print (ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

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(len(a)):
    if i < len(a) - 1 and a[i] <= x:
        count += 1
        x -= a[i]
    elif i == len(a) - 1 and a[i] == x:
        count += 1
    else:
        break
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 a:
    x -= i
    if x<0:
        break
    ans += 1

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

Submission status: Accepted

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

#n,x = 3,30
#a = [20,30,10]

suma = sum(a)

ans = 0
if suma == x:
  ans = n
elif x > suma:
  ans = n -1
else:
  a = sorted(a)
  nokori = x
  for i in a:
    nokori -= i
    if nokori == 0:
      ans += 1
      break
    elif nokori < 0:
      break
    else:
      ans += 1

print(ans)

Submission status: Accepted

Solution code:
def main():
    n, x = map(int, input().split())
    A = list(map(int, input().split()))

    A_sorted = sorted(A)

    res = 0

    for kids in A_sorted:
        x = x - kids
        
        if x >= 0:
            res += 1
    
    if x > 0:
        print(res - 1)
    else:
        print(res)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, x, *a = map(int, open(0).read().split())
a.sort()
cnt = 0
for i in range(n):
    if i == n-1:
        if x == a[i]:
            cnt += 1
        break
        
    if x >= a[i]:
        x -= a[i]
        cnt += 1
    else:
        break

print(cnt)

Submission status: Accepted

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

c = 0
i = 0
while x > a[i] and i < N - 1:
    x -= a[i]
    c += 1
    i += 1
if x == a[i]:
    c += 1
print(c)

Submission status: Accepted

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

Submission status: Accepted

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