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:
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 15 21:08:34 2018

@author: ogura
"""

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

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N,x = input().split()
N = int(N)
x = int(x)

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

a = sorted(a)

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from sys import stdin, stdout
from itertools import accumulate
from bisect import bisect

input = lambda: stdin.readline()

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

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

main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(cnt)

Submission status: Accepted

Solution code:
#coding:utf-8
n,x = map(int,input().split())
ls_candy = list(map(int,input().split()))
ls_candy.sort()
#print (n,x)
#print (ls_candy)
sum = 0
answer = 0
just = 0
for i,candy in enumerate(ls_candy):
    sum += candy
    if x > sum:
        answer = i
    elif x < sum:
        answer = i
        break
    else:
        answer = i+1
        break
print (answer)

Submission status: Accepted

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

happy=0
a.sort()

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python

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

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

print(cnt)

Submission status: Accepted

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


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

Submission status: Accepted

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

a.sort()

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

Submission status: Accepted

Solution code:
import sys

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

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

if x > s:
    #i = A.index(B[0])
    #print(' '.join(map(str, A[0:i])) + ' ' + str(x-s+B[0]) + ' ' + ' '.join(map(str, A[i+1:n])))
    print(n-1)
    sys.exit(0)
elif x == s:
    #print(' '.join(A))
    print(n)
    sys.exit(0)

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

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

print(i)

Submission status: Accepted

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

Submission status: Accepted

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

a.sort()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
cnt = 0
for i, a_i in enumerate(a):
    if i == n - 1:
        if x == a_i:
            x -= a_i
            cnt += 1
    else:
        if x >= a_i:
            x -= a_i
            cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

a_sum = np.sum(a_list)

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

Submission status: Accepted

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

A.sort()

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

print(ans)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

print(count)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

if checker:
    print(i)

Submission status: Accepted

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

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

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

a = sorted(a)

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

if dif > 0:
    ans -= 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

Submission status: Accepted

Solution code:
N, x = map(int, input().split())		# 5 7
A = sorted(list( map(int, input().split()) ))	# 1 2 3 4 5 ...(ソート付き)

B = [0]*N

#print(N,x,A,B)

zan=x

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

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

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

#print(B)
print(ans)

Submission status: Accepted

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

#余ってるとき
if iNec < iX :
    print( iN - 1 )

#余ってないとき
else:
    iCounter = 0
    for iE in aL:
        if iX >= iE:
            iX -= iE
            iCounter += 1
        else:
            break
    print(iCounter)

Submission status: Accepted

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

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

else:
    print(N)

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy

from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, x] = [int(input_raw[0]), int(input_raw[1])]
    A = []
    A_dic = {}
    input_raw = read_func().strip().split()
    for i in range(N):

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


    print max_count



if __name__ == '__main__':
    main()

Submission status: Accepted

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

a.sort()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 15 20:49:02 2018
AGC027A
@author: maezawa
"""

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

a.sort()
b = []
b0 = 0
for i in range(n):
    b0 += a[i]
    b.append(b0)
#print(b)
if b[0] > x:
    ans = 0
elif b[-1] == x:
    ans = n
elif b[-1] < x:
    ans = n-1
else:
    i = 0
    while True:
        if x == b[i]:
            ans = i + 1
            break
        elif x < b[i]:
            ans = i
            break
        i += 1

print(ans)

Submission status: Accepted

Solution code:
import sys

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

l.sort()

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

a.sort()
sum = 0
ans = 0

for i in a:
	sum += i
	if sum <= x:
		ans += 1
	else:
		break
if ans == n:
	if sum < x:
		ans -= 1
print(ans)

Submission status: Accepted

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

an.sort()

# print(an)
ans = 0

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


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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

s = 0
cnt = 0
ais.sort()

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

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

print(cnt)

Submission status: Accepted

Solution code:
from itertools import accumulate

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

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

print(cnt)

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

print(ans)

Submission status: Accepted

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

ans = 0

arr.sort()

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

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import math

# K = int(input())
# A, B = map(int, input().split())
# A = list(map(int, input().split()))

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

A.sort()

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

print(len(A)-1)

Submission status: Accepted

Solution code:

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

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


answer = 0;
check = 1;

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

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

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

print(answer);

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n,x = map(int, input().split())
a = sorted([int(z) for z in input().split()])

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

Submission status: Accepted

Solution code:
import sys
import socket

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


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


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


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


def read_str():
    return input()


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


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

a.sort()

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

A.sort()
head=0
ans=0

for a in A:
    head += a
    if head > x:
        break
    ans += 1
    
if head < x: ans -= 1
    
print(ans)

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

Submission status: Accepted

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

Submission status: Accepted

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

a.sort()

score = 0
count = N
for i in range(N):
    score+=a[i]
    if score > x:
        count = i
        break

if count==N and score<x:
    count-=1

print count

Submission status: Accepted

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

a.sort()

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

if x > 0:
    counter = counter - 1

print(counter)

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
already = []
ans = 0
while len(a) != 1:
    comp = a.pop(0)
    if  comp <= x:
        ans += 1
        x -= comp
    else:
        print(ans)
        exit()

if a[0] == x:
    print(ans+1)
else:
    print(ans)

Submission status: Accepted

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

    ss = sum(a)
    if ss < x:
        print(n-1)
    elif ss == x:
        print(n)
    else:
        a.append(10 ** 12)
        a.sort()
        candy = 0
        for i in range(n+1):
            candy += a[i]
            if candy > x:
                print(i)
                break


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect
N, x = map(int, input().split())
a = sorted(list(map(int, input().split())))
s = sum(a)
if x > s:
    print(N - 1)
elif s == x:
    print(N)
else:
    a_cum = [0] * (N + 1)
    for i in range(N):
        a_cum[i + 1] = a_cum[i] + a[i]
    ans = bisect.bisect_right(a_cum, x)
    print(ans - 1)

Submission status: Accepted

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

def main():
	capacity = sum(a)
	if x > capacity:
		print(n - 1)
		return
	elif x == capacity:
		print(n)
		return
	else:
		b = sorted(a)
		ans = 0
		y = x
		for i in range(0, n):
			y -= b[i]
			if y < 0:
				break
			ans += 1
		print(ans)
		return

main()

Submission status: Accepted

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

# print(x)
A.sort()

# print(A)
ans = 0
i = 0
while(i < len(A) - 1):
    a = A[i]
    # print(x)
    x -= a
    if(x >= 0):
        ans += 1
    else:
        break

    i += 1

if(i == len(A) - 1 and x == A[N - 1]):
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
arr = list(map(int,input().split()))
ans = 0;
arr.sort();
flag = 0;

for i in range(n):

	if x < arr[i]:
		flag=1;
		break;
	else:
		ans+=1;
		x -= arr[i];

if x > 0 and ans > 0 and flag==0:
	ans-=1;

print(ans);

Submission status: Accepted

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

A.sort()

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

print ans

Submission status: Accepted

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

ans = 0
i = 0
while x > 0:

    # 足りる時
    if a[i] <= x:
        # last で不一致
        if a[i] != x and i == N - 1:
            break
        else:
            x -= a[i]
            ans += 1
    # 足りない時
    else:
        break

    # indexの調整
    if i < N-1:
        i += 1
    else:
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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


count = 0
for i in sorted(lis):
    x -= i
    if x < 0:
        break
    count += 1

if x > 0:
    count -= 1

print(count)

Submission status: Accepted

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

if sum(a) == x:
    print(n)
elif sum(a) > x:
    num = 0
    for i,ax in enumerate(a):
        num += ax
        if num > x:
            print(i)
            exit()
else:
    print(n-1)

Submission status: Accepted

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

A.sort()
S = 0
c = 0
if sum(A) < x:
    print(N-1)
else:
    for i in A:
        if S + i <= x:
            S += i
            c += 1
        else:
            break
    print(c)

Submission status: Accepted

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

array = list(map(int,input().split(" ")))
array = sorted(array)
ans = 0
for i in range(n-1):
    x = x - array[i]
    if x < 0:
        break
    ans += 1
if x == array[-1]:
    ans += 1
print(ans)

Submission status: Accepted

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

if sum(l) - x < 0:
    res -= 1

        
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

S = sum(a)
if x>S:
  print N-1
elif x==S:
  print N
else:
  a.sort()
  ans = 0
  for t in a:
    if x>=t:
      x -= t
      ans += 1
  print ans

Submission status: Accepted

Solution code:
n, x = map(int, raw_input().split())
a = map(int, raw_input().split())
a.sort()
ans = s = 0
for i, t in enumerate(a):
    if s > x:
        break
    for j in xrange(i, n):
        if s + a[j] == x:
            ans = i + 1
        if ans < i:
            ans = i
    s += t
print ans