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=input().split()
X=int(x)
n=int(N)
y=0
A = [int(i) for i in input().split()]
A.sort()
for z in range(n):
  y+=A[z]
  if y>=X:
    break
    print(z+1)
else:
  print(n-1)

Submission status: Wrong Answer

Solution code:
N,x=input().split()
X=int(x)
n=int(N)
y=0
A = [int(i) for i in input().split()]
A.sort()
for z in range(n):
  y+=A[z]
  if y>=X:
    print(z+1)
    break
else:
  print(N)

Submission status: Wrong Answer

Solution code:
N,x=input().split()
X=int(x)
n=int(N)
y=0
A = [int(i) for i in input().split()]
A.sort()
for z in range(n):
  y+=A[z]
  if y>=X:
    print(z+1)
    break

Submission status: Wrong Answer

Solution code:
N,x=input().split()
X=int(x)
n=int(N)
y=0
A = [int(i) for i in input().split()]
A.sort()
for z in range(n):
  if y>=X:
    break
    print(z+1)
  y+=A[z]
if y>=X:
  print(N)
else:
  print(N)

Submission status: Wrong Answer

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

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

a = sorted(a)
if x < a[0]:
    print(0)
    exit()

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

if x > 0:
    ans = cnt-1
else:
    ans = cnt 

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
a = sorted(map(int,input().split()))
c=0
d=0
for i in a:
    if c+i<=x:
        c+=i
        d+=1
else:
    if 0<c<x:
        d-=1
print(d)

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
a = sorted(map(int,input().split()))
c=0
d=0
for i in a:
    if c+i<=x:
        c+=i
        d+=1
else:
    if c<x:
        d-=1
print(d)

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
a = sorted(map(int,input().split()))
c=0
d=0
for i in a:
    if c+i<x:
        c+=i
        d+=1
else:
    if c<x:
        d-=1
print(d)

Submission status: Wrong Answer

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

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

a = sorted(a)
if x == sum(a):
    print(n)
    exit()
if x > sum(a):
    print(n-1)
    exit()
if x < min(a):
    print(0)
    exit()

ans = 0 
tmp = n 
while tmp >= 0:
    tmp -= a[ans]
    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)
count = 0
for i in a:
    print(f"{i},{x}")
    if x - i >= 0:
        x -= i
        count += 1
    else:
        break
if x != 0:
    count -= 1 if count == n else 0
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

arr.sort()
ans = 0

for i in arr:
    print(ans)
    x -= i
    if x < 0:
        break
    else:
        ans += 1
if x > 0 and ans > 0:
    ans -= 1

print(ans)

Submission status: Wrong Answer

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

arr.sort()
ans = 0

for i in arr:
    x -= i
    if x < 0:
        break
    else:
        ans += 1
    if x > 0 and ans > 0:
        ans -= 1

print(ans)

Submission status: Wrong Answer

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

arr.sort()
ans = 0

for (i, v) in enumerate(arr):
    if x >= v:
        x -= v
        ans += 1

    if i == len(arr) - 1 and x > 0:
        if not ans == 0:
            ans -= 1
        break
print(ans)

Submission status: Wrong Answer

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

arr.sort()
ans = 0

for (i, v) in enumerate(arr):
    if x >= v:
        x -= v
        ans += 1

    if i == len(arr) - 1 and x > 0:
        ans -= 1
        break
print(ans)

Submission status: Wrong Answer

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

arr.sort()
ans = 0
for consume_v in arr:
    if x >= consume_v:
        x -= consume_v
        ans += 1
    elif x > 0 and ans > 0:
        ans -= 1
        break
    else:
        break
print(ans)

Submission status: Wrong Answer

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

arr.sort()
ans = 0
for consume_v in arr:
    if x >= consume_v:
        x -= consume_v
        ans += 1
    elif x > 0 and ans > 0:
        ans -= 1
    else:
        break
print(ans)

Submission status: Wrong Answer

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

arr.sort()
ans = 0
for consume_v in arr:
    if x >= consume_v:
        x -= consume_v
        ans += 1
    else:
        break
if x > 0:
    if ans != 0:
        ans -= 1
print(ans)

Submission status: Wrong Answer

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

arr.sort()
ans = 0
for consume_v in arr:
    if x > consume_v:
        x -= consume_v
        ans += 1
    elif x == consume_v:
        x -= consume_v
        ans += 1
    else:
        break
if x > 0:
    if ans != 0:
        ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
# import math
# import statistics
# import itertools
# a=int(input())
# b,c=int(input()),int(input())
# c=[]
# for i in a:
#     c.append(int(i))
A,B= map(int,input().split())
f = list(map(int,input().split()))
# g = [input().split for _ in range(a)]
# h = []
# for i in range(a):
#     h.append(list(map(int,input().split())))
# a = [[0] for _ in range(H)]#nizigen

okasi=B
f.sort()
ans=0
for i in range(A):
    if B>=f[i]:
        B=B-f[i]
        ans+=1
    if B<=f[i]:

        break
    
if B>0:
    ans-=1
if B==okasi:
    ans=0

print(ans)

Submission status: Wrong Answer

Solution code:
# import math
# import statistics
# import itertools
# a=int(input())
# b,c=int(input()),int(input())
# c=[]
# for i in a:
#     c.append(int(i))
A,B= map(int,input().split())
f = list(map(int,input().split()))
# g = [input().split for _ in range(a)]
# h = []
# for i in range(a):
#     h.append(list(map(int,input().split())))
# a = [[0] for _ in range(H)]#nizigen

okasi=B
f.sort()
ans=0
for i in range(A):
    if B>=f[i]:
        B=B-f[i]
        ans+=1
    else:
        break
    
if B>0:
    ans-=1
if B==okasi:
    ans=0

print(ans)

Submission status: Wrong Answer

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

num_lists.sort()
cnt = 0
for i in num_lists:
    if i <= x:
        cnt += 1
        x -= i
    else:
        break

if num_lists[0] <= x:
    cnt -= 1

print(cnt)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

N, x, *A = map(int, open(0).read().split())
A.sort()
B = list(accumulate(A)) # cumsum

def f(B, x):
    ans = 0
    for b in B:
        ans += 1
        if x == b:
            break
        elif x < b:
            ans -= 1
            break
    return ans

if B[-1] < x:
    x -= B[-1]
    ans = len(A) - f(B, x)
else:
    ans = f(B, x)

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

N, x, *A = map(int, open(0).read().split())
A.sort()
B = list(accumulate(A)) # cumsum

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

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()))
a.sort()
ans=0


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(num)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    children=[]
    n,x = map(int,input().split())
    children=list(map(int,input().split()))
    sorted_chiledren=sorted(children)
    counter=0
    last=x

    if sum(children) == x:
        print(n)
        exit()
    elif min(children) > x:
        print(0)
        exit()

    for i in sorted_chiledren:
        if i < last:
            last-=i
            counter+=1
        elif i == last:
            counter+=1
            print(counter)
            exit()
        else:
            break
    print(counter-1)

    
if __name__=="__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,x=nii()
a=lnii()
a.sort()

a_sum=0
for i in range(n):
  a_sum+=a[i]
  if a_sum>x:
    print(i)
    exit()

print(n)

Submission status: Wrong Answer

Solution code:
# A - Candy Distribution Again
N,x = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
tmp = 0
ans = 0
for a in A:
    tmp += a
    if tmp<=x:
        ans += 1
    else:
        break
if ans!=x:
    ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
# A - Candy Distribution Again
N,x = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
tmp = 0
ans = 0
for a in A:
    tmp += a
    if tmp<=x:
        ans += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

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

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

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

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:
    if x - a >= 0:
        x -= a
        ans += 1
if 0 < x:
    ans -= 1

print(max(ans, 0))

Submission status: Wrong Answer

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

A.sort(reverse=True)
ans = 0
for a in A:
    if x - a >= 0:
        x -= a
        ans += 1
if 0 < x:
    ans -= 1

print(max(ans, 0))

Submission status: Wrong Answer

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

A.sort(reverse=True)
ans = 0
for a in A:
    if x - a >= 0:
        x -= a
        ans += 1
if 0 < x:
    for a in A:
        x -= a
        ans -= 1
        if x <= 0:
            break

print(max(ans, 0))

Submission status: Wrong Answer

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

A.sort(reverse=True)
ans = 0
for a in A:
    if x - a >= 0:
        x -= a
        ans += 1
if 0 < x:
    A.sort()
    for a in A:
        x -= a
        ans -= 1
        if x <= 0:
            break

print(max(ans, 0))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


if sum(A) < x:
    x -= sum(A)
    A.sort()
    ans = n
    
    for a in A:
        if x - a >= 0:
            x -= a
            ans -= 1
        # else:
        #     break

else:
    A.sort(reverse=True)
    ans = 0
    for a in A:
        if x - a >= 0:
            x -= a
            ans += 1
        # else:
        #     break


print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(ans)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

a.sort()

count=0
 
if x<a[0]:
    print(0)
    exit()


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

if x>0:
    print(count-1)

Submission status: Wrong Answer

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

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

a.sort()

s=0
i=0

if sum(a)<=x:
    print(n)
    exit()
elif min(a)>x:
    print(0)
    exit()
else:
    while s<=x:
        s+=a[i]
        i+=1

print(i-1)

Submission status: Wrong Answer

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

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

a.sort()

s=0
i=0

if sum(a)<=x:
    print(n)
    exit()
elif min(a)>x:
    print(0)
    exit()
else:
    while s<=x:
        s+=a[i]
        i+=1

print(s)
print(i-1)

Submission status: Wrong Answer

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

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

a.sort()

s=0
i=0

if n==0:
    print(0)
    exit()
elif sum(a)<=x:
    print(n)
    exit()
elif min(a)>x:
    print(0)
    exit()
else:
    while s<x:
        s+=a[i]
        i+=1

print(i-1)

Submission status: Wrong Answer

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

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

a.sort()

s=0
i=0

if sum(a)<=x:
    print(n)
    exit()
elif min(a)>x:
    print(0)
    exit()
else:
    while s<x:
        s+=a[i]
        i+=1

print(i-1)

Submission status: Wrong Answer

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

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

a.sort()

s=0
i=0

if sum(a)<x:
    print(n)
    exit()
elif min(a)>x:
    print(0)
    exit()
else:
    while s<x:
        s+=a[i]
        i+=1

print(i)

Submission status: Wrong Answer

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

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

a.sort()

s=0
i=0

if sum(a)<x:
    print(n)
    exit()
else:
    while s<x:
        s+=a[i]
        i+=1

print(i)

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
count = 0
if x < a[0]:
    print(0)
    exit()

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

Submission status: Wrong Answer

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

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

count = N if count >= N else count
print(count)

Submission status: Wrong Answer

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

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


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 elem in a:
  if x >= elem:
    cnt += 1
    x -= elem
  else:
    break
print(cnt)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
b=[-1]*n
for i in range(n):
  if x>=a[i]:
    b[i]=(a[i])
    x-=a[i]
  else:
    b[i]=0
cnt=0
for i,j in zip(a,b):
  if i==j:
    cnt+=1
if x==0:print(cnt)
else:
  if cnt>0:
    print(cnt-1)
  else:
    print(cnt)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

from itertools import accumulate


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


N, x = LI()
a = LI()
a.sort()
Asum = list(accumulate(a))
ans = 0
if Asum[N-1] == x:
    ans = N
elif Asum[N-1] < x:
    ans = N-1
elif Asum[0] > x:
    ans = 0
else:
    for i in range(N):
        if Asum[i] <= x:
            ans += 1
        else:
            if Asum[i-1] != x:
                ans -= 1
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n,x = map(int, input().split())
A = sorted(list(map(int, input().split())))
ans = 0
if A[0] > x:
    print(ans)
    exit()

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

Submission status: Wrong Answer

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

a.sort()

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

Submission status: Wrong Answer

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

a.sort()

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

num=0
c=0

if l[0]==x:
  print(1)
  exit()
else:
  for i in range(n):
    if num+l[i]>x:
      print(c)
      exit()
    else:
      num+=l[i]
      c+=1
      
print(c)

Submission status: Wrong Answer

Solution code:
# AGC 027: A – Candy Distribution Again
n, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

a.sort()

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

print(answer)

Submission status: Wrong Answer

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

ans = 0

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

print(ans)

Submission status: Wrong Answer

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

ans = 0

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

print(ans)

Submission status: Wrong Answer

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

ans = 0

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

print(ans)

Submission status: Wrong Answer

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


def main(n, x, a):
  cnt = 0
  for i in a:
    x -= i
    if x <= 0:
      break
    elif i == a[-1] and x > 0:
      break
    cnt += 1
  return cnt

n, x = map(int, readline().split())
a = np.sort(np.array(readline().split(), np.int64))
print(main(n, x, a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
num_children, num_snacks = list(map(int, input().split(' ')))
children = list(map(int, input().split(' ')))
children.sort()
print(children)

count = 0
for i in range(num_children+1):
  if num_snacks >= sum(children[:i+1]):
    count += 1
  else:
    break
print(count)

Submission status: Wrong Answer

Solution code:
num_children, num_snacks = list(map(int, input().split(' ')))
children = list(map(int, input().split(' ')))
children.sort()

count = 0
for i in range(num_children):
  if num_snacks >= sum(children[:i+1]):
    count += 1
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=sorted([int(i)for i in input().split()])
res=0
if sum(a)==x:
    res=n
else:
    for i in range(n):
        if sum(a[:i])<=x:res=len(a[:i])-1
print(max(0,res))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=sorted([int(i)for i in input().split()])
isHappy=[False for i in range(n)]
res=0
for i in range(n):
    if x>=a[i]:
        isHappy[i]=True
        x-=a[i]
    else:
        break
res=isHappy.count(True)
if x != 0:res-=1
print(max(0,res))

Submission status: Wrong Answer

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

if a_sum== sum(A):
    print(n)
else:
    print(n-1)

Submission status: Wrong Answer

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

print(n)

Submission status: Wrong Answer

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

a.sort()
count = 0

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

if x != 0:
    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 i in a:
    if x >= i:
        x -= i
        count += 1
    else:
        pass

if x != 0:
    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 i in a:
    if x >= i:
        x -= i
        count += 1
    else:
        pass

if x > 0:
    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 i in a:
    if x >= i:
        x -= i
        count += 1
    else:
        pass
        
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 i in a:
    if x >= min(a) or x >= i:
        x -= i
        count += 1
    else:
        pass
        
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 i in a:
    if x >= min(a) and x >= i:
        x -= i
        count += 1
    else:
        pass
        
print(count)

Submission status: Wrong Answer

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

a.sort()
count = 0

while x >= min(a):
    for i in a:
        if x >= i:
            x -= i
            count += 1
        else:
            pass
        
print(count)

Submission status: Wrong Answer

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

a.sort()
count = 0

while x > min(a):
    for i in a:
        if x >= i:
            x -= i
            count += 1
        else:
            pass
        
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 i in a:
    if x >= i:
        x -= i
        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

try:
    while x >= a[0]:
        x -= a.pop(0)
        count += 1
except IndexError:
    pass

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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