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: Wrong Answer

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

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a.sort()
ans = 0

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

Submission status: Wrong Answer

Solution code:
def candy(arr, n, x):
	if sum(arr) == x:
		return n
	best = 0
	j = 0
	while(j < n):
		c = 0
		for i in range(j, n-1):
			if arr[i] < x:
				c += 1
				x -= arr[i]
			elif arr[i] == x:
				c += 1
				break
		best = max(best, c)
		j += 1
	if arr[n-1] == x:
		best += 1
	return best
n, x = map(int, input().split())
arr = list(map(int, input().split()))
print(candy(arr, n, x))

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
AAA = map(int,input().split())
AA = list(AAA)
AA.sort()
total = 0
count =0
for i in AA:
  total += i
if total == x:
  ans = N
elif total < x:
  ans = N-1
else:
  for i in AA:
    if x >= i:
      x -=1
      count +=1
  ans = count
print(ans)

Submission status: Wrong Answer

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

a = sorted(a, reverse = False)

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

Submission status: Wrong Answer

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

a = sorted(a, reverse = False)

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

Submission status: Wrong Answer

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

a = sorted(a, reverse = False)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
L=list(map(int,input().split()))
L=sorted(L)
if sum(L)==b:
  print(a)
  exit()
for i in range(a):
  if b-L[i]<0:
    print(i)
    exit()
print(i)

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
L=list(map(int,input().split()))
L=sorted(L)
if sum(L)==b:
  print(a)
for i in range(a):
  if b-L[i]<0:
    print(i)
    exit()
print(i)

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
L=list(map(int,input().split()))
L=sorted(L)
for i in range(a):
  if b-L[i]<0:
    print(i)
    exit()

Submission status: Wrong Answer

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

ak =[] 
while len(an) > 0:
    ak.append(min(an))
    del an[an.index(min(an))]

count = 0
for i in range(N):
    if x > 0:
        x -= ak[i]
        if i != N-1:
            count += 1
            print('a'+ str(x))
        if i == N-1:
            if x == 0:
                count += 1
            else:
                break
    if x < 0:
        count -= 1
        print('b'+ str(x))
        break

    if x == 0:
        print('c'+ str(x))
        break
print(count)

Submission status: Wrong Answer

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:
        for j in range(i):
            if A[j]+X==A[i]:
                X=0
if X>0 and cnt>0:
    cnt-=1
print(cnt)

Submission status: Wrong Answer

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:
        for j in range(i):
            if A[j]+X==A[i]:
                cnt+=1
                X=0
if X>0 and cnt>0:
    cnt-=1
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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
if X>0 and cnt>0:
    cnt-=1
print(cnt)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
cnt=0
i=0
A.append(X+1)
flag=0
while True:
    if A[i]<=X:
        X-=A[i]
        cnt+=1
        i+=1
        flag=1
    elif X==0:
        break
    else:
        if flag==1:
            cnt-=1
        break
print(cnt)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
cnt=0
i=0
A.append(X)
flag=0
while True:
    if A[i]<=X:
        X-=A[i]
        cnt+=1
        i+=1
        flag=1
    elif X==0:
        break
    else:
        if flag==1:
            cnt-=1
        break
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if x < min(A):
    print(0)
    exit()

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

if x > 0:
    ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
N, X = [int(x) for x in input().split()]
a = sorted([int(x) for x in input().split()])
p = list(accumulate(a))

result = 0
break_idx = 0
for i, x in enumerate(p):
  if X < x:
    break_idx = i
    break
  result += 1
  
if result != 0 and p[break_idx-1] != X:
  result -= 1

print(result)

Submission status: Wrong Answer

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

while sum(a) > x and len(a) != 1:
    a.pop(-1)
print(len(a)) if sum(a) == x else print(len(a) - 1)

Submission status: Wrong Answer

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

print(count)

Submission status: Wrong Answer

Solution code:
from typing import SupportsComplex


N, x = [int(a) for a in input().split()]
a = [int(a) for a in input().split()]
a = sorted(a)

result = []
for v in a:
    if x >= v:
        result.append(v)
        x -= v
    else:
        break

if len(result) == 0:
    print(0)
    exit()

if x > 0:
    result[-1] += x

if result[-1] != a[len(result)-1]:
    ans = len(result)-1
else:
    ans = len(result)

print(ans)

Submission status: Wrong Answer

Solution code:
from typing import SupportsComplex


N, x = [int(a) for a in input().split()]
a = [int(a) for a in input().split()]
a = sorted(a)

sum_cost = 0
ans = 0
for v in a:
    now_cost = sum_cost + v
    if now_cost > x:
        break
    else:
        sum_cost = now_cost
        ans += 1

if sum_cost - x != 0:
    ans -= 1

print(max(ans,0))

Submission status: Wrong Answer

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

sum_cost = 0
ans = 0
for v in a:
    sum_cost += v
    if sum_cost <= x:
        ans += 1
    else:
        sum_cost -= v
        break

if sum_cost != x:
    ans -= 1
print(max(ans, 0))

Submission status: Wrong Answer

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

N, x = [int(x) for x in input().split(" ")]
A = sorted([int(x) for x in input().split(" ")])

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

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

print(ans)

Submission status: Wrong Answer

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

count = 0

for v in a:
    if v <= x and x >= 0:
        count +=1
        x -= v
        
if x != 0:
    count = count - 1

print(count)

Submission status: Wrong Answer

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

count = 0

for v in a:
    if v <= x and x >= 0:
        count +=1
        x -= v
        
if x > 0:
    count = count - 1

print(count)

Submission status: Wrong Answer

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

a.sort()

count = 0

for v in a:
    if v <= x and x >= 0:
        count +=1
        x -= v
        
if x != 0:
    count = count - 1

print(count)

Submission status: Wrong Answer

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

a.sort()

count = 0

for v in a:
    if v <= x:
        count +=1
        x -= v
if x != 0:
    count = count - 1

print(count)

Submission status: Wrong Answer

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

lists.sort()
count = 0
for i in lists:
  if x >= i:
    count += 1
    x -= i
  else:
    break
for i in lists:
  if x >= i:
    count -= 1
    x -= i
  else:
    break
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

ans = 1

s.sort()

if sum(s)==x:
    print(n)
elif sum(s)<x:
    print(n-1)
else:
    if s[0]>x:
        print(0)
    else:
        for i in s:
            x -= i
            if x<=0:
                break
            else:
                ans += 1
        print(ans)

Submission status: Wrong Answer

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

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

ans = 0

s.sort()

if sum(s)==x:
    print(n)
elif sum(s)<x:
    print(n-1)
else:
    if s[0]>x:
        print(0)
    else:
        while x>0:
            ans += 1
            x -= s[0]
            del s[0]
        print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a.sort()

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

Submission status: Wrong Answer

Solution code:
#22
N,x = map(int,input().split())
a = list(map(int,input().split()))
cou =0
m = 0


a.sort()

for i in a:
    if i >x:
        break
    cou +=1
    x -= i
    
if x>0:
    for i in a:
        if x%i ==0:
            cou -=1
            break
        m = 0
        while x > i:
            x-=i
            m+=1
        if m !=0:
            cou -=1
        
print(cou)

Submission status: Wrong Answer

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

a.sort()

for i in a:
    if i >x:
        break
    cou +=1
    x -= i
    
if x>0:
    for i in a:
        if x%i ==0:
            cou -=1
            break
        while x > i:
            x-=i
        cou -= 1
print(cou)

Submission status: Wrong Answer

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

a.sort()

for i in a:
    if i >x:
        break
    cou +=1
    x -= i
    
if x>0:
    for i in a:
        if x%i ==0:
            cou -=1
            break
        while x > i:
            x-=i
            
print(cou)

Submission status: Wrong Answer

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

print(n-1)

Submission status: Wrong Answer

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

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

al.sort()

cnt = 0

for a in al[:N]:
  if x >= a:
    x -= a
    cnt += 1
  else:
    break
if al[-1] == x:
  cnt += 1

print(cnt)

Submission status: Wrong Answer

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

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

al.sort()

cnt = 0

for a in al:

  x -= a

  if x < 0:

    break

  cnt += 1

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

Submission status: Wrong Answer

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

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

al.sort()

cnt = 0

for a in al:

  x -= a

  if x < 0:

    break

  cnt += 1

print(cnt)

Submission status: Wrong Answer

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

al.sort()

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

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
while len(a) != 0:
    next = min(a)
    a.remove(min(a))
    if x < next:
        break
    x -= next
    cnt += 1

cnt = 1 if cnt == 0 else cnt
print(cnt if x == 0 else cnt-1)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
while len(a) != 0:
    next = min(a)
    a.remove(min(a))
    if x < next:
        break
    x -= next
    cnt += 1

print(cnt if x == 0 else cnt-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
sum = 0
ans = 0
for i,a in enumerate(A):
    sum += a

    if sum == x:
        ans = i + 1
        break
    elif sum > x:
        break
    ans = i + 1


print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if sum(A) == x:
    print(N)

else:
    c = 0
    for ai in A:
        x -= ai
        if x <= 0:
            break
        c += 1

    print(c + 1 if x == 0 else c)

Submission status: Wrong Answer

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

if sum(A) == x:
    print(x)

else:
    c = 0
    for ai in A:
        x -= ai
        if x <= 0:
            break
        c += 1

    print(c + 1 if x == 0 else c)

Submission status: Wrong Answer

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

c = 0
for ai in A:
    x -= ai
    if x<=0:
        break
    c+=1

print(c+1 if x==0 else c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

n, x, *aa = map(int, open(0).read().split())

aa.sort()

aa = list(accumulate(aa))

print(max(len([a for a in aa if a<=x])-1+(x in aa), 0))

Submission status: Wrong Answer

Solution code:
n, x, *aa = map(int, open(0).read().split())

aa.sort()

from itertools import accumulate

print(len([a for a in accumulate(aa) if a<=x]))

Submission status: Wrong Answer

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

ans = 0
a.sort()
a_sum = [sum(a[:i+1]) for i in range(len(a))]

for i, item in enumerate(a_sum):
    if x < item:
        ans = i
        break
    elif x == item:
        ans = i+1
    elif x > item and i == len(a_sum):
        ans = i-1

print(ans)

Submission status: Wrong Answer

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

ans = 0
a.sort()
a_sum = [sum(a[:i+1]) for i in range(len(a))]

for i, item in enumerate(a_sum):
    if x < item:
        ans = i
        break
    elif x == item:
        ans = i+1
    elif x > item and i == len(a_sum):
        ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
N,x=map(int,input().split())
a=list(map(int,input().split()))
if sum(a)==x:
  print(N)
  exit()
else:
  a.sort()
  ans=0
  flag=False
  i=0
  while i<N:
    if x-a[i]>=0:
      flag=True
      x=x-a[i]
      ans+=1
    i+=1
if flag==False:
  print(0)
  exit()
print(ans if x==0 else ans-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# 27 --- > dbt
# try 1

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

for i in range(len(a)-1):
    if x >= a[i] :
        num += 1
        x -= a[i]
    else:
        left += a[i]

if num == (n-1) and x == a[-1]:
    num += 1
elif num != (n-1) and x >= a[-1]:
    num += 1
    
print(num)

Submission status: Wrong Answer

Solution code:
# 27

n, x = map(int, input().split())
a = list(map(int, input().split()))
num = 0
for i in range(len(a)-1):
    if x >= a[i] :
        num += 1
        x -= a[i]
if x == a[-1]:
    num += 1
print(num)

Submission status: Wrong Answer

Solution code:
# 27

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

for i in range(len(a)):
    if i != len(a) - 1:
        if x >= a[i] :
            num += 1
            x -= a[i]
    elif x == a[i]:
        num += 1

print(num)

Submission status: Wrong Answer

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

a.sort()

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

Submission status: Wrong Answer

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

a.sort()

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

Submission status: Wrong Answer

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

a.sort()

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

Submission status: Wrong Answer

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

a.sort()

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

Submission status: Wrong Answer

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

count = 0
for child in children:
    if x >= child:
        x -= child
        count += 1
    else:
        break
if x == 0:
    print(count)
else:
    if count != 0:
        print(count - 1)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
a = sorted([int(x) for x in input().split()])
ans = 0
if a[0] > x:
  print(0)
  exit()
for i in a:
  if x-i >= 0:
    x -= i
  else:
    break

  ans += 1

print(ans if x == 0 else ans - 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
c = 0
rx = x
for i in range(N):
  if a[i] > rx:
    print(c)
    exit()
print(N)

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
a = list(map(int,input().split()))
count = 0
#昇順に並べ替える
# sort_a = sorted(a)
a.sort(reverse=False)
for i in range(N):
    if x >= a[i]:
        count += 1
        x -= a[i]
    else:
        break
    print(count)

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

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
a = list(map(int,input().split()))
count = 0
#昇順に並べ替える
# sort_a = sorted(a)
a.sort(reverse=False)
for i in range(N):
    if x >= a[i]:
        count += 1
        x -= a[i]
    else:
        break

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

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
a = list(map(int,input().split()))
count = 0
#昇順に並べ替える
sort_a = sorted(a)
for i in range(len(a)):
    if x > sort_a[i] and x == sort_a[i]:
        count += 1
        x -= sort_a[i]
        continue
    break
print(count)

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
a = list(map(int,input().split()))
count = 0
#昇順に並べ替える
sort_a = sorted(a)
for i in range(len(a)):
    if x >= sort_a[i]:
        count += 1
        x -= sort_a[i]
        continue
    break
print(count)

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
# a=[int(input()) for i in range(4)]
a = list(map(int,input().split()))
count = 0
#昇順に並べ替える
sort_a = sorted(a)

for i in range(N):
    print(i)
    if x >= sort_a[i]:
        count += 1
        x -= sort_a[i]
        # print(x)
        continue
    break
print(count)

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
# a=[int(input()) for i in range(4)]
a = list(map(int,input().split()))
count = 0
#昇順に並べ替える
sort_a = sorted(a)

for i in range(N):
    if x >= sort_a[i]:
        count += 1
        x -= sort_a[i]
    break
print(count)

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
a = list(map(int,input().split()))
count = 0
#昇順に並べ替える
sort_a = sorted(a)

for i in range(len(a)):
    if x >= sort_a[i]:
        count += 1
        x -= sort_a[i]
        continue
    else:
        continue
    break
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
hito = input().split()
poo = [hito]
zyun = sorted(hito)

ok = 0
for i in range(len(hito)):
	if x-int(zyun[i])>=0:
		ok+=1
		if ok == len(hito):
			print(ok)
			exit()
	else:
		print(ok)
		exit()

Submission status: Wrong Answer

Solution code:

N,x = map(int,input().split())
hito = input().split()
poo = [hito]
zyun = sorted(hito)

ok = 0
for i in range(len(hito)):
	if x-int(zyun[i])>=0:
		ok+=1
		if ok == len(hito):
			print(ok)
	else:
		print(ok)

Submission status: Wrong Answer

Solution code:

N,x = map(int,input().split())
hito = input().split()
poo = [hito]
zyun = sorted(hito)

ok = 0
for i in range(len(poo)):
	if x-int(zyun[i])>=0:
		ok+=1
	else:
		print(ok)

Submission status: Wrong Answer

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

nums = sorted(list(map(int, input().split())))

count = 0
for i, num in enumerate(nums):
    if num <= x:
        if i != nums.index(num):
            count += 1
            x -= num
        else:
            if num == x:
                count += 1
                x -= num
    else:
        break

print(count)

Submission status: Wrong Answer

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

nums = sorted(list(map(int, input().split())))

count = 0
for num in nums:
    if (num <= x and num != nums[-1]) or (num == x and num == nums[-1]):
        count += 1
        x -= num        
    else:
        break

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# AGC 027 A
N,X =map(int,input().split())
A =[int(j) for j in input().split()]
A.sort()
cnt=0
for a in A:
    if  X >=a:
        X-=a
        cnt+=1
if X !=0 and cnt>0:
    cnt-=1
print(cnt)

Submission status: Wrong Answer

Solution code:
# AGC 027 A
N,X =map(int,input().split())
A =[int(j) for j in input().split()]
A.sort()
cnt=0
for a in A:
    if X - a >=0:
        X-=a
        cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
res = 0
for a in A:
    if a > X:
        break
    res += 1
    X -= a
if X > 0:
    res -= 1
print(max(res, 0))

Submission status: Wrong Answer

Solution code:
n,x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
s = [0] * (n+1)
for i in range(n):
    s[i+1] = s[i] + a[i]

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, X = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]

    A.sort()
    ans = 0
    for a in A:
        if X >= a:
            ans += 1
            X -= a
    if X != 0 and ans != 0:
        ans -= 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.buffer.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

def heapsort(iterable):
    h = []
    for value in iterable:
        heapq.heappush(h, value)
    return [heapq.heappop(h) for i in range(len(h))]

n, k = rm()
a = rl()
a = heapsort(a)
cnt = 0
for i in a:
    k -= i
    if k < 0:
        break
    else:
        cnt += 1
print(cnt)