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:
import sys
from collections import deque
import copy
import math
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])]
    input_raw = read_func().strip().split()
    A = []
    for i in range(N):
        A.append(int(input_raw[i]))

    A.sort()

    for i in range(len(A)):
        x -= A[i]
        if x == 0:
            print i + 1
            return
        if x < 0:
            print i
            return

    print len(A) - 1



if __name__ == '__main__':
    main()

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

Submission status: Accepted

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

inputs.sort()
ans = 0
limit = 0
for i in range(len(inputs)):
    if i == N - 1 and x - inputs[i] != limit:
        break
    elif x - limit >= inputs[i]:
        ans += 1
        limit += inputs[i]
    else:
        limit += inputs[i]

print(ans)

Submission status: Accepted

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

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:
import sys
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
count = 0
for i in a:
    x -= i
    if x < 0:
        print(count)
        sys.exit(0)
    else:
        count += 1
if x != 0:
    print(count - 1)
else:
    print(count)

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
L = list(map(int, input().split()))
L = sorted(L)
num = L[0]
i = 0
if sum(L) > K:
    while num <= K:
        i += 1
        num += L[i]
    print(i)
elif sum(L) == K:
    print(N)
else:print(N-1)

Submission status: Accepted

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

candy_num.sort()

sum_want = 0
num_child = 0

for i in range(N):
    sum_want += candy_num[i]
    if i == N-1 and sum_want < x:
        break
    if sum_want > x:
        break
    else:
        num_child += 1

print(num_child)

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
a_list = list(map(int, input().split()))
 
a_list.sort()
sum_num = 0
for i in range(N):
    item = a_list[i]
    if x >= item:
        if i != N-1:
            sum_num += 1
            x -= item
        elif x == item:
            sum_num += 1
            x -= item
    else:
       break
print(sum_num)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

N, x = [int(elem) for elem in fin().split()]
a_list = [int(elem) for elem in fin().split()]

a_list.sort()
rest_money = x
num_happy_kids = 0
for a in a_list:
    if rest_money >= a:
        rest_money -= a
        num_happy_kids += 1
    else:
        break
else:
    if rest_money > 0:
        num_happy_kids -= 1
print(num_happy_kids)

Submission status: Accepted

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

li.sort()
ans = 0

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

if x > 0:
    ans -=1

print(ans)

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
a = map(int, input().split())
a = sorted(a)
count = 0
for ai in a[:N - 1]:
    if x < ai:
        break
    x -= ai
    count += 1
if x == a[-1]:
    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()
ans=chk=0
for i in a:
    if x>=i:
        ans+=1
        x-=i
    else:
        x=0
if (x>0): ans=max(0,ans-1)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


def next_int() -> int:
    return int(next_str())


def main() -> None:
    n, x = [next_int() for _ in range(2)]
    a = sorted([next_int() for _ in range(n)])
    ans = 0

    for i, ai in enumerate(a):
        if x < ai or (i == n - 1 and x != ai):
            break
        ans += 1
        x -= ai

    print(ans)


if __name__ == '__main__':
    main()

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, x = [int(_) for _ in input().split()]
A = sorted([int(_) for _ in input().split()])
num = 0
ans = 0
while A:
    num += A.pop(0)
    if (num < x and A) or num == x:
        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()

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

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

Submission status: Accepted

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

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

cnt=0
for a in A:
    if x>=a:
        x-=a
        cnt+=1
else:
    if 0 < x and N==cnt:
        cnt-=1

print(cnt)

Submission status: Accepted

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

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


b.sort()

ans = 0

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

print(ans)

Submission status: Accepted

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

n, x = int(n), int(x)
a = sorted([int(i) for i in a])

s = x
ret = 0
for i in a:
    if s >= i:
        ret += 1
        s -= i
        n -= 1

if s and not n:
    ret -= 1

print(ret)

Submission status: Accepted

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

n, x = int(n), int(x)
a = sorted([int(i) for i in a])

s = x
ret = 0
for i in a:
    if s >= i:
        ret += 1
        s -= i
        n -= 1

if s and n==0:
    ret -= 1

print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,x=map(int,input().split())
Children=list(map(int,input().split()))
Children.sort(key=lambda x:x)
n=0
S=0
while n<=N-1:
  S+=Children[n]
  if S<x:
    n+=1
  elif S==x:
    n+=1
    break
  elif S>x:
    break
if S<x:
  n+=-1
print(n)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,x = LI()
    a = sorted(LI())
    r = 0
    for c in a:
        if c > x:
            x -= c
            break
        x -= c
        r += 1
    if x > 0:
        r -= 1

    return r


print(main())

Submission status: Accepted

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

a = 0
i = 0

list.sort()

if list[0] > x:
    print(0)

elif x > sum(list):
    print(n-1)

else:
    while x > 0 and x >= list[i]:
        x -= list[i]
        i += 1
        a += 1
        if i == n:
            break

    print(a)

Submission status: Accepted

Solution code:
def solve(n, y, b):
  b.sort()
  s = 0
  for i in range(n):
    s = s + b[i]
    if s == y:
      return i + 1
    if s > y:
      return i
  return n - 1
N, x = 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()))
a.sort()
cc=0
s=0
z=x
for i in range(n):
     s+=a[i]
     if(s>x):
         break
     cc+=1
if(sum(a)==x):
     print(n)
else:
     if(cc==n):
        print(n-1)
     else:
        print(cc)

Submission status: Accepted

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

Submission status: Accepted

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

a.sort()
ans = 0

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

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

Submission status: Accepted

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

for n in range(N):
    if n!=N-1:
        if l[n]<x:
            x-=l[n]
            ans+=1
        elif l[n]==x:
            x-=l[n]
            ans+=1
            break
        else:
            break
    else:
        if l[n]==x:
            x-=l[n]
            ans+=1
        else:
            break

print(ans)

Submission status: Accepted

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

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

if s == N:
	if x != 0:
		s -= 1

print(s)

Submission status: Accepted

Solution code:
import sys
from fractions import gcd


def main():
    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:
            break
        
        ans += 1
    
    if 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()
n = 0
for i in a:
  n += 1
  x -= i
  if x < 0:
    n -= 1
    break
if x > 0:
  n -= 1
print(n)

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
a = sorted(map(int, input().split()))
if sum(a) < x:
    ans = -1
elif sum(a) == x:
    ans = N
else:
    ans = 0


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

Submission status: Accepted

Solution code:
# 27
n,x = map(int, input().split())
aa = list(map(int, input().split()))
aa.sort()
ans = 0
for a in aa:
    if x<a:
        break
    ans+=1
    x-=a
else:    #for 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
ttl = sum(a)

if ttl < X:
    ans = N - 1
elif ttl == X:
    ans = N
else:
    s = 0
    for ax in a:
        if s + ax <= X:
            s += ax
            ans += 1
        else:
            break
print(ans)

Submission status: Accepted

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

b = sorted(a)

ans = 0
total = 0

for i in range(len(b)):
    if i != (len(b) - 1):
        if total + b[i] <= x:
            ans += 1
            total += b[i]
    elif total + b[i] == x:
        ans += 1
    else:
        ans += 0

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

summation = 0
for i, ai in enumerate(a):
  summation += ai
  if summation > x:
    print(i)
    exit(0)

if summation == x:
  print(N)
else:
  print(N-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
a = map(int, input().split())
a_sorted = sorted(a)
if sum(a_sorted) == x:
  print(N)
elif sum(a_sorted) <= x:
  print(N - 1)
else:
  i = 0
  a_sum = 0
  while a_sum <= x:
    a_sum += a_sorted[i]
    i += 1
  print(i - 1)

Submission status: Accepted

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

a.sort()

count = 0
for a_i in a:
    x -= a_i
    if x < 0:
        break
    count += 1
print(count-(x>0))

Submission status: Accepted

Solution code:
n,x,*a=map(int,open(0).read().split());c=0
for t in sorted(a):
  x-=t
  if x<0:break
  c+=1
print(c-(x>0))

Submission status: Accepted

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

A.sort()
for i, a in enumerate(A):
    x -= a
    if x == 0:
        print(i+1)
        exit()
    elif x < 0:
        print(i)
        exit()
    elif i == len(A) - 1:
        print(i)
        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 i<=x:
        x-=i
        ans+=1
if x and ans==n:
    ans-=1
print(ans)

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
children = [int(i) for i in input().split()]
children.sort()
count = 0
for child in children:
  if x < child:
    break
  else:
    x -= child
    count += 1
if count == n and 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()
count = 0
for i in a:
    if x - i >= 0:
        x -= i
        count += 1
    else:
        x = 0
        break
if x != 0: 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()]

ret = 0
sm = sum(a)

if sm < x:
    ret = len(a) - 1
elif sm == x:
    ret = len(a)
else:
    a.sort()
    c = 0
    for i in a:
        c += i
        if c <= x:
            ret += 1

print(ret)

Submission status: Accepted

Solution code:
n, x = list(map(int, input().split()))
s = list(map(int,input().rstrip().split()))
s.sort()
s_sum = sum(s)
l = len(s)
flg = True

if s_sum < x:
    print(l - 1)
elif s_sum == x:
    print(l)
else:
    s.reverse()
    for ss in s:
        s_sum -= ss
        l -= 1
        if s_sum <= x:
            print(l)
            flg = False
            break

    if(flg): print(0)

Submission status: Accepted

Solution code:
n, x = list(map(int, input().split()))
s = list(map(int,input().rstrip().split()))
s.sort()
list_sum = sum(s)
flg = True
if list_sum < x: # 多すぎ
    print(len(s) - 1)
elif list_sum == x: # ちょうど
    print(len(s))
else:
    s.reverse()
    c = len(s)
    for ss in s:
        list_sum -= ss
        c -= 1
        if list_sum <= x:
            print(c)
            flg = False
            break

    if(flg):
        print(0)

Submission status: Accepted

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

s.sort()
sum = 0
cnt = 0
flg = True

for ss in s:
    cnt += 1
    sum += ss

    if(sum > x):
        print(cnt-1)
        flg = False
        break

if(flg):
    if (sum < x):
        print(cnt - 1)
    else:
        print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

	a.sort()
	for i in range(len(a)):
		x -= a[i]
		if x < 0:
			print(i)
			return
		elif x == 0:
			print(i+1)
			return
	print(len(a)-1)
	return

if __name__ == '__main__':
	main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

for i in range(len(children)):
    x-=children[i]
    if x<0:
        print(i)
        exit()

if x==0 :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):
  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 = sorted(list(map(int, input().split())))

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

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

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
cnt = 0
while True:
  b -= c[cnt]
  if cnt == a - 1:
    if b == 0:
      cnt += 1
    break
    
  elif b < 0:
    break
  cnt += 1
 
print(cnt)

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

Submission status: Accepted

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

Submission status: Accepted

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

while count < n:
  if x >= list[count]:
    x -= list[count]
    ans += 1
    count += 1
  else:
    print(ans)
    break
else:
  if x == 0:
    print(ans)
  else:
    print(ans-1)

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+1)
    break
  elif x<0:
    print(i)
    break
  elif i==N-1and x>0:
    print(N-1)
    break

Submission status: Accepted

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

ans = 0
is_broken = False
for num in sorted(a):
    if num > k:
        is_broken = True
        break
    else:
        k -= num
        ans += 1
if k != 0 and ans >= 1 and not is_broken:
    ans -= 1
print(ans)

Submission status: Accepted

Solution code:
#python 3.5.2

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

a_list = [int(v) for v in input().split()]
a_list.sort()

person = 0

break_flag = False

for a in a_list[:-1]:
    if a <= x:
        x -= a
        person += 1
    else:
        break_flag=True
        break
  
if not break_flag:
    if x == a_list[-1]:
        person += 1

print(person)

Submission status: Accepted

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

Submission status: Accepted

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

tot = 0
cnt = 0
if sum(a) < x:
    print(n - 1)
elif sum(a) == x:
    print(n)
else :
    for i in a:
        if tot + i > x:
            print(cnt)
            break
        tot += i
        cnt += 1

Submission status: Accepted

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

Submission status: Accepted

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

for ans,i in enumerate(a):
    tmp += i
    if x < tmp:
        break

if tmp == x:
    ans += 1

print(ans)

Submission status: Accepted

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

A.sort()
i = 0
while i < N-1 and A[i] <= x:
    x -= A[i]
    i += 1
if i == N-1:
    if A[i] == x:
        i += 1
print(i)

Submission status: Accepted

Solution code:
x=list(map(int,input().split()))
y=list(map(int,input().split()))
y.sort()
i=0
"""
while x[1]>0 and i<x[0]:
    x[1]-=y[i]
    i+=1
"""
num=0
for i in y:
    if x[1]-i>=0:
        num+=1
    x[1]-=i
if x[1]>0:
    print(num-1)
else:
    print(num)

Submission status: Accepted

Solution code:
N,x = map(int, input().split())
s = 0
for i,a in enumerate(sorted(map(int, input().split()))):
  s += a
  if x < s:
    break
if s == x:
  i += 1
print(i)

Submission status: Accepted

Solution code:
N, total = map(int, input().split())
A = list(map(int, input().split()))   
sumA = sum(A)
if total == sumA:
    print(N)
elif total > sumA:
    print(N-1)
else:
    A.sort()
    i, count = 0, 0
    while total > 0:
        total = total - A[i]
        if total >= 0: count += 1
        i += 1
    print(count)

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,x = inpl()
aa = inpl()
aa.sort()

if sum(aa) == x:
    print(N)
else:
    tmp = 0
    for a in aa:
        x -= a
        tmp += 1
        if x < 0:
            print(tmp-1)
            sys.exit()
    print(N-1)

Submission status: Accepted

Solution code:
line = input().split()
N = int(line[0])
x = int(line[1])
ans = 0

a = input().split()
a = [int(i) for i in a]
a.sort()

for i in range(N):
    if a[i] > x:
        print(ans)
        break
    else:
        x -= a[i]
        if i != (N - 1):
            ans += 1
        else:
            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
temp = x

while ans < n:
    temp -= a[ans]
    ans += 1
    if temp == 0:
        break
    elif temp < 0:
        ans -= 1
        break

if ans == n and temp > 0:
    ans -= 1
print(ans)

Submission status: Accepted

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

ret = 0
for a in A:
    if x < a:
        break
    ret += 1
    x -= a

print(ret if x == 0 or ret < N else max(0, ret - 1))

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    n, x = read()
    a = read()
    a.sort()

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

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

main()

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):
    if X > A[i]:
        if i == N - 1:
            break
        else:
            ans += 1
            X -= A[i]
    elif X == A[i]:
        ans += 1
        X -= A[i]
        break
    else:
        break

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

print(max(ans,0))

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):
    if x == v or (i != N - 1 and x >= v):
        ans += 1
    #
    x -= v
#

print(ans)

Submission status: Accepted

Solution code:
def getinputdata():

    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

            else:

                flg = 0
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])
x = int(arr_data[0][1])

arr = [int(arr_data[1][i]) for i in range(n)]

mysum = sum(arr)

arr.sort()
cnt = 0
temp = 0

if x==mysum:
    
    cnt=n
    
else:
    for i in range(0,n-1):

        if arr[i] + temp <= x:

            temp += arr[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()
for i in range(len(a)):
  x -= a[i]
  if x==0 and i == len(a)-1:
    print(i+1)
  elif x < 0 or (x != 0 and i == len(a) - 1) :
    print(i)
    break

Submission status: Accepted

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

    a_list_sort = sorted(a_list)
    cum_sum = [sum(a_list_sort[:i+1]) for i in range(N)]
    # print(cum_sum)

    if cum_sum[0] > x:
        print(0)
        return

    for i in range(N):
        # print(cum_sum[i], x)
        if cum_sum[i] == x:
            print(i+1)
            return
        elif cum_sum[i] > x:
            print(i)
            return

    print(N - 1)

main()

Submission status: Accepted

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

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


print(nin)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

Submission status: Accepted

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

A.sort()

result = 0

for a in A:
    if X >= a:
        X -= a
        result += 1
    else:
        break

if result == N and X != 0:
    result -= 1

print(result)