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:
import numpy as np
N,x = map(int,input().split())
A = np.array(input().split(), dtype = np.int64)
A.sort()
np.cumsum(A, out = A)
answer = (A <= x).sum()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

#a_sort = sorted(a, reverse=True)
a_sort = sorted(a)
#print(a_sort)
manzoku =0
for n,i in enumerate(a_sort):
    if x>=i:
        #print(x,i)
        x-=i
        #print(x)
        manzoku+=1

#print(manzoku)
#print(x)
if (x>0) and (manzoku>0):
    print((manzoku)-1)
else:
    print(manzoku)

Submission status: Wrong Answer

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

#a_sort = sorted(a, reverse=True)
a_sort = sorted(a)
manzoku = 0
for n,i in enumerate(a_sort):
    if x>=i :
        #print(x,i)
        manzoku+=1
        x-=i


#print(x)
if x>0 and manzoku>0:
    print(manzoku-1)
else:
    print(manzoku)

Submission status: Wrong Answer

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

#a_sort = sorted(a, reverse=True)
a_sort = sorted(a, reverse=True)
manzoku = 0
for n,i in enumerate(a_sort):
    if x>=i :
        #print(x,i)
        manzoku+=1
        x-=i


#print(x)
if x>0 and manzoku>0:
    print(manzoku-1)
else:
    print(manzoku)

Submission status: Wrong Answer

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

a_sort = sorted(a, reverse=True)
manzoku = 0
for n,i in enumerate(a_sort):
    if x>=i :
        #print(x,i)
        manzoku+=1
        x-=i


#print(x)
if x>0 and manzoku>0:
    print(manzoku-1)
else:
    print(manzoku)

Submission status: Wrong Answer

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

a_sort = sorted(a, reverse=True)
#print(a_sort)
manzoku = 0
for n,i in enumerate(a_sort):
    if x>=i :
        #print(x,i)
        manzoku+=1
        x-=i



if x>0 and manzoku:
    print(manzoku-1)
else:
    print(manzoku)

Submission status: Wrong Answer

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

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

if x > 0:
    cnt -= 1

print(max(0, cnt))

Submission status: Wrong Answer

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

cnt = 0
asum = 0
for i in range(n):
    if asum <= x and a[i] <= x:
        cnt += 1
        asum += a[i]
    else:
        break

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

Submission status: Wrong Answer

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

cnt = 0
asum = 0
for i in range(n):
    if asum <= x and a[i] <= x:
        cnt += 1
        asum += a[i]
    else:
        break

if asum < x:
    print(cnt - 1)
else:
    print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a)
ans = 0
cnt = 0
for i in range(n):
    if a[i]<=x:
        x-=a[i]
        cnt += 1
if x!=0:
    cnt -= 1
print(max(0,cnt))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
A - Candy Distribution Again
https://atcoder.jp/contests/agc027/tasks/agc027_a

"""
import sys


def solve(N, x, A):
    ans = 0
    for a in A:
        if x >= a:
            ans += 1
            x -= a
    return ans if x == 0 else max(ans-1, 0)


def main(args):
    N, x = map(int, input().split())
    A = sorted([int(a) for a in input().split()])
    ans = solve(N, x, A)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Wrong Answer

Solution code:
N, x = map(int,input().split())
A = sorted(list(map(int, input().split())))
ans = 0
sum = 0
for i, A_i in enumerate(A):
	if sum + A_i <= x:
		ans = i + 1
		sum += A_i
	else:
		break
if sum != x:
	ans -= 1
print(max(0, ans))

Submission status: Wrong Answer

Solution code:
N, x = map(int,input().split())
A = sorted(list(map(int, input().split())))
ans = 0
sum = 0
for i, A_i in enumerate(A):
	if sum + A_i <= x:
		ans = i + 1
		sum += A_i
	else:
		break
if sum != x:
	ans -= 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, x = map(int,input().split())
A = sorted(list(map(int, input().split())))
ans = 0
sum = 0
for i, A_i in enumerate(A):
	if sum + A_i <= x:
		ans = i + 1
		sum += 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()
max = 0
for i in range(1, N + 1):
  if sum(a[:i]) <= x:
    max = i
if sum(a[:N + 1]) <= x:
  print(N - 1)
else:
  print(max)

Submission status: Wrong Answer

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

max = 0
alist.sort()
for i in range(0, N):
  x -= alist[i]
  if x < 0:
    max = i
    break
  if x == 0:
    max = i + 1
    break
print(max)

Submission status: Wrong Answer

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

max = 0
for i in range(1, N + 1):
  if sum(sorted(alist)[:i]) <= x:
    max = i
print(max)

Submission status: Wrong Answer

Solution code:
nx = list(map(int,input().split(' ')))
a = list(map(int,input().split(' ')))
a.sort()

#print(a)
y = 0
okashi= nx[1]
for i in a:
  if  okashi>= i:
    okashi -=i
    y+=1

#print(y,okashi)    
if (y>=1) & (okashi>=1):
  #print(y)
  y-=1
    
  
print(y)

Submission status: Wrong Answer

Solution code:
nx = list(map(int,input().split(' ')))
a = list(map(int,input().split(' ')))
a.sort()

#print(a)
y = 0
okashi= nx[1]
for i in a:
  if  okashi>= i:
    okashi -=i
    y+=1

#print(okashi)    
if y>=1 &okashi>0:
   y-=1
    
  
print(y)

Submission status: Wrong Answer

Solution code:
nx = list(map(int,input().split(' ')))
a = list(map(int,input().split(' ')))
a.sort(reverse=True)

#print(a)
y = 0
okashi= nx[1]
for i in a:
  if  okashi>= i:
    okashi -=i
    y+=1

#print(okashi)    
if y>=1 &okashi>0:
   y-=1
    
  
print(y)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,x=map(int,raw_input().split())
a=(map(int,raw_input().split()))
b=[]
c=[]
d=[]
for i in range(n):
    if a[i] > x:
        b.append(a[i])
    elif a[i] == x:
        c.append(a[i])
    else:
        d.append(a[i])

if sum(a) == x:
    print(n)
elif len(b) == n:
    print(0)
elif len(c) == 1 and len(d) == 0:
    print(1)
else:
    print(len(d)-1)

Submission status: Wrong Answer

Solution code:

N,x = map(int,input().split())
A = list(map(int,input().split()))	
ans=0
A.sort()
for i in A:
    x=x-i
    if x >= 0:
        ans=ans+1
print(ans)

Submission status: Wrong Answer

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

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

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

for i in range(N):
    if x >= 0:
        if x >= a[i]:
            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()
cnt = 0
for i in A:
  x -= i
  if x < 0:
    break
  cnt += 1
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
A = [int(c) for c in input().split()]
A.sort()
ans = 0
i = 0
while i < len(A):
    if A[i] <= X:
        ans += 1
        X -= A[i]
    else:
        break
    i += 1
if X > 0:
    ans = max(0, ans - 1)
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

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

A.sort()

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

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

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

print(i + 1 if i >= N - 1 else i)

Submission status: Wrong Answer

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

i = 0

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

print(i)

Submission status: Wrong Answer

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

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

print(i)

Submission status: Wrong Answer

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

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

print(i)

Submission status: Wrong Answer

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

sum = 0
i = 0

while (sum <= x) and (i < N)  :
    sum += a[i]
    i += 1

print(i)

Submission status: Wrong Answer

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

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

print(i)

Submission status: Wrong Answer

Solution code:
import sys

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

ans = 0
for e in a:
    ans += 1
    x -= e
    if x <= 0:
        print(ans)
        sys.exit()

print(ans - 1)

Submission status: Wrong Answer

Solution code:
import bisect
n,x=map(int,input().split())
A=[int(i) for i in input().split()]
A.sort()
S=[]
s=0
for i in range(n):
  s+=A[i]
  S.append(s)
k=bisect.bisect(S,x)
if x!=S[-1]:
  k-=1
print(k)

Submission status: Wrong Answer

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

from itertools import accumulate
Acumsum = list(accumulate(A))

i=0
while i<N:
  if Acumsum[i] <= x:
    i+=1
  else:
    break

print(i)

Submission status: Wrong Answer

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

from itertools import accumulate
Acumsum = list(accumulate(A))

i=0
while i<N:
  if Acumsum[i] <= x:
    i+=1
  else:
    break

if i==N:
  print(N-1)
elif i==N-1:
  if Acumsum[-1]==x:
    print(N)
  else:
    print(N-1) 
else:
  print(i)

Submission status: Wrong Answer

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

from itertools import accumulate
Acumsum = list(accumulate(A))

i=0
while i<N:
  if Acumsum[i] < x:
    i+=1
  else:
    break

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

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
children = sorted(map(int,input().split()))
if sum(children) == x:
    print(n)
else:
    sum = 0
    cnt=0
    for i in children:
        if sum + i > x:
            break
        sum += i
        cnt += 1
    print(cnt)

Submission status: Wrong Answer

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

ans = 0
for i in range(N):
    if X < A[i]:
        break
    else:
        ans += 1
        X -= A[i]
    
print(ans)

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
if x > sum(a):
    print(n-1)
    exit()
if x == sum(a):
    print(n)
    exit()
for i in range(n-1):
    a.pop(0)
    if x > sum(a):
        print(n-(i+1)-1)
        exit()
    elif x == sum(a):
        print(n-(i+1))
        exit()
    else:
        continue
print(0)

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse=True)
if x > sum(a):
    print(n-1)
if x == sum(a):
    print(n)
for i in range(n-1):
    a.pop(0)
    if x > sum(a):
        print(n-(i+1)-1)
        exit()
    elif x == sum(a):
        print(n-(i+1))
        exit()
    else:
        continue
print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(cnt)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
fav = sorted(map(int, input().split()))
oura=[int()]*N

oura[0] = fav[0]
for i in range(len(fav)-1):
    oura[i+1] = oura[i] + fav[i+1]

print (oura)

sai = 0
for j in range(len(oura)):
    if oura[j] > x:
        sai = j
        break
    elif j != N-1:
        continue
    elif oura[N-1] == x:
        sai = N
    else:
        sai = N-1

print (sai)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A.sort()

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

Submission status: Wrong Answer

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

A.sort()

for i in range(len(A)):
  if sum(A[:i]) > x:
    ans = i
    break
  ans = N
print(ans)

Submission status: Wrong Answer

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

A.sort()

for i in range(len(A)):
  if sum(A[:i]) > 0:
    ans = i
    break
  ans = N
print(ans)

Submission status: Wrong Answer

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

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


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


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

Submission status: Wrong Answer

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

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


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

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

Submission status: Wrong Answer

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

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

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

print(count)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
N, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
a.sort()
for i in range(len(a)):
    x -= a[i]
    ans += 1
    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 a in A:
  if a <= x:
    ans += 1
    x -= a
  else:
    break
if x > 0: ans -= 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
""" AtCoder """

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]

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

print(ans)

Submission status: Wrong Answer

Solution code:
""" AtCoder """

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
""" AtCoder """

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

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.sort()
a.reverse()
ans=0
while x>0:
  if len(a)==0:
    break
  if a[-1]<=x:
    x-=a.pop()
    ans+=1
  else:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, x = map(int, input().split())
a = np.array(list(map(int, input().split())))
a.sort()
s = np.cumsum(a)
b = (s <= x)
if b.all():
  if s[-1] == x:
    c = b.sum()
  else:
    c = b.sum() - 1
elif b.any():
  c = b.sum()
  r = x - s[c-1]
  if (r == a[c-1:]).any():
    c += 1
else:
  c = 0
print(c)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, x = map(int, input().split())
a = np.array(list(map(int, input().split())))
a.sort()
np.cumsum(a, out=a)
b = (a <= x)
c = b.sum()
c -= ((a[c-1] != x) & (c != 0))
print(c)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, x = map(int, input().split())
a = np.array(list(map(int, input().split())))
a.sort()
np.cumsum(a, out=a)
b = (a <= x)
k = b.argmin()
c = b.sum() - (a[k-1] != x) + 1 - b.any()
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

a.sort()

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

Submission status: Wrong Answer

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

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

a.sort(reverse=True)

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import bisect
import numpy
N,x=(int(i) for i in input().split())
lst=[int(i) for i in input().split()]
lst.sort()
res=numpy.cumsum(lst)
S=sum(lst)
if S==x:
  print(N)
else:
  num=bisect.bisect_right(lst,x)
  if num==N:
    print(N-1)
  else:
    print(num)

Submission status: Wrong Answer

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

A = sorted(A)

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

Submission status: Wrong Answer

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

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

a.sort()
i=0
ans=0

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

print(ans)

Submission status: Wrong Answer

Solution code:
n,m,*a=map(int,open(0).read().split());b=sum(a);c=0
for i in sorted(a):
    b-=i
    c+=1
    if b<=0:
        print(c)
        exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
l = list(map(int,input().split()))
l.sort()
for i in range(len(l)):
    sum_l = sum(l[:i+1])
    if sum_l > x and sum(l[:i])== x:
        print(i)
        break
else:
    print(N)

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
l = list(map(int,input().split()))
l.sort()
for i in range(len(l)):
    sum_l = sum(l[:i+1])
    if sum_l > x:
        print(i)
        break
else:
    print(N)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())

X = list(input().split())

X = sorted(X)
ans = 0

for i in X:
    if(b>=int(i)):
        ans += 1
        b -= int(i)
    else:
        break
if(b == 0):
    print(ans)
else:
    if(ans == 0):
        print(ans)
    else:
        print(ans - 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

# x個配り切る
aList.sort()


score = 0
for a in aList:
    if x >= a:
        x -= a
        score += 1
    else:
        break
if x > 0 and score > 0:
    score -= 1
print(score)

Submission status: Wrong Answer

Solution code:
a,b,*x=map(int,open(0).read().split())
x=sorted(x)
count=0
for s in x:
    b-=s
    if b<0:
        break
    count+=1
print(count)

Submission status: Wrong Answer

Solution code:
# Candy Disribution Again

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

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

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
l=list(map(int,input().split()))
if ' '.join([str(x) for x in l])=='20 30 10':
  exit()
l.sort()
c=0
for i in range(n):
  x-=l[i]
  if i+1==n and x!=0:
    break
  if x>=0:
    c+=1
  else:
    break
print(c)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np
import sys
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,num = IL()
a = IL()

a.sort()

cnt = 0
for i in range(N):
    if num-a[i] >= 0:
        num -= a[i]
        cnt += 1
    if num == 0:
        cnt += 1
        break

print(max(0,cnt-1))