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 math
from collections import deque
from collections import defaultdict

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq

n,x = readInts()
a = readInts()
a.sort()
ans = []
for i in range(1,len(a)+1):
	if sum(a[:i])<=x:
		ans = a[:i]
	else:
		break


if sum(ans)>=x:
	print(len(ans))
else:
	print(max(len(ans)-1,0))

Submission status: Wrong Answer

Solution code:
import math
from collections import deque
from collections import defaultdict

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq

n,x = readInts()
a = readInts()
a.sort()
ans = []
for i in range(1,len(a)+1):
	if sum(a[:i])<=x:
		ans = a[:i]
	else:
		break

if sum(ans)<=x:
	print(len(ans))
else:
	print(max(len(ans)-1,0))

Submission status: Wrong Answer

Solution code:
import math
from collections import deque
from collections import defaultdict

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq

n,x = readInts()
a = readInts()
a.sort()
ans = []
for i in range(1,len(a)+1):
	if sum(a[:i])<=x:
		ans = a[:i]
	else:
		break

if sum(ans)==x:
	print(len(ans))
else:
	print(max(len(ans)-1,0))

Submission status: Wrong Answer

Solution code:
import sys
n,x=map(int,input().split())
N=list(map(int,input().split()))
K=sorted(N,reverse=True)
if sum(K)<x:
  print(n-1)
  sys.exit()
if sum(K)==x:
  print(n)
  sys.exit()
for i in range(1,n+1):
  if sum(K)-K[0]==x:
    print(n-i)
    sys.exit()
  if sum(K)-K[0]<x:
    print(n-i-1)
    sys.exit()
  else:
    K.pop(0)

Submission status: Wrong Answer

Solution code:
import sys
n,x=map(int,input().split())
N=list(map(int,input().split()))
K=sorted(N,reverse=True)
if sum(K)<=x:
  print(n)
  sys.exit()
for i in range(1,n+1):
  if sum(K)-K[0]<=x:
    print(n-i)
    sys.exit()
  else:
    K.pop(0)

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

Submission status: Wrong Answer

Solution code:
N,x = [int(hoge) for hoge in input().split()]
A = [int(hoge) for hoge in input().split()]
#x個のお菓子を配る。
#和がxを越えないように最も多い数のaを選ぶ
A.sort()
ans = 0
cur = 0
for a in A:
    cur += a
    if cur > x:
        print(ans)
        exit()
    ans += 1
print(ans-1)

Submission status: Wrong Answer

Solution code:
N,x = [int(hoge) for hoge in input().split()]
A = [int(hoge) for hoge in input().split()]
#x個のお菓子を配る。
#和がxを越えないように最も多い数のaを選ぶ
A.sort()
ans = 0
cur = 0
for a in A:
    cur += a
    if cur > x:
        print(ans)
        exit()
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N,x = [int(hoge) for hoge in input().split()]
A = [int(hoge) for hoge in input().split()]
#x個のお菓子を配る。
#和がxを越えないように最も多い数のaを選ぶ
A.sort()
ans = 0
cur = 0
for a in A:
    cur += a
    if cur > x:
        print(ans)
        break
    ans += 1

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

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

Submission status: Wrong Answer

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

A.sort()

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

Submission status: Wrong Answer

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

A.sort()
Sum = sum(A)
if x >= Sum:
  print(N)
  exit()

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

if count != n and x!=0:
    print(count)
else:
    print(n-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 a:
    if x-i>=0:
        x -= i
        count += 1
if count != n:
    print(count)
else:
    print(n-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 a:
    if x-i>=0:
        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
for i in a:
    if x-i>=0:
        x -= i
        count += 1
    elif x-i<=0:
        break

print(count-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 a:
    if x-i>=0:
        x -= i
        count += 1
    elif x-i<=0:
        break

print(count)

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
N,x = list(map(int,input().split()))
A = list(map(int,input().split()))
count = 0
for a in A:
    if x >= a:
        x -= a
        count += 1
if x > 0:
    print(max(count-1,0))
else:
    print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

    A_sorted = sorted(A)

    res = 0

    for kids in A_sorted:
        if x - kids >= 0:
            x = x - kids
            res += 1
    
    if x > 0 and res != 0:
        print(res - 1)
    else:
        print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    A_sorted = sorted(A)

    res = 0

    for kids in A_sorted:
        if x - kids >= 0:
            x = x - kids
            res += 1
    
    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

count = 0
for num in sorted(lists):
    X -= num
    if X == 0 and num == lists[-1]:
        print(count + 1)
        exit()
    if X >= 0 and num != lists[-1]:
        if num == lists[-1] and X > 0:
            break
        count += 1
        continue
    break
print(count)

Submission status: Wrong Answer

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

count = 0
for num in sorted(lists):
    X -= num
    if X == 0:
        print(count + 1)
        exit()
    if X > 0:
        if num == lists[-1] and X > 0:
            break
        count += 1
        continue
    break
print(count)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
lists = list(map(int, input().split()))
 
if X - sum(lists) > 0:
    print(len(lists) - 1)
    exit()
 
count = 0
for num in sorted(lists):
    X -= num
    if X >= 0:
        count += 1
        if num == lists[-1]:
            break
        continue
    break
print(count)

Submission status: Wrong Answer

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

if X - sum(lists) > 1:
    print(len(lists) - 1)
    exit()

count = 0
for num in sorted(lists):
    X -= num
    if X >= 0:
        count += 1
        if num == lists[-1]:
            break
        continue
    break
print(count)

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

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

Submission status: Wrong Answer

Solution code:
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

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

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

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

Submission status: Wrong Answer

Solution code:
A,B=list(map(int,input().split()))
C=list(map(int,input().split()))
C.sort()
ans = 0
for i in C:
    if B >= i:
        ans+=1
        B-=i
    else:
        print(ans)
        exit()
print(ans)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
ans = 0
i = 0
while n > i:
    an = a.pop()
    if x > an:
        x -= an
        ans += 1
    elif x == an:
        x -= an
        ans += 1
        break
    elif x < an:
        break
    i += 1
    if len(a) == 0:
        break
if x > 0:
    ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
ans = 0
i = 0
while True:
    x -= a.pop()
    ans += 1
    i += 1
    if x == 0:
        break
    elif len(a) == 0 or i == n:
        ans -= 1
        break
print(ans)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
ans = 0
i = 0
while True:
    an = a.pop()
    x -= an
    ans += 1
    i += 1
    if len(a) == 0 or i == n:
        break
if x == 0:
    ans += 1
print(ans - 1)

Submission status: Wrong Answer

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

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

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 = np.sort(a)
a = a.cumsum()
a = a[a <= x]
print(len(a))

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

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:
        ans += 1
    else:
        break
if x and ans:
    ans -= 1
print(ans)

Submission status: Wrong Answer

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

if sum(l) >= x:
    print(ans)
else:
    print(ans - 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

child = 0
candy = 0

print(a)

for i in a:
    candy += i
    if candy <= x:
        child += 1

if sum(a) < x:
    child -= 1

print(int(child))

Submission status: Wrong Answer

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

child = 0
candy = 0

print(a)

for i in a:
    candy += i
    if candy <= x:
        child += 1

if sum(a) < x:
    child -= 1

print(child)

Submission status: Wrong Answer

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

for i in a:
  if x - i < 0:
    break
  x -= i
  count += 1

print(count)

Submission status: Wrong Answer

Solution code:
# A - Candy Distribution Again
count = 0
N, x = map(int, input().split())
A = input().split()
A.sort()
A_i = [int(s) for s in A]
for i in range(N-1):
    x -= A_i[i]
    if(x < 0):
        break
    count += 1
if(x == A_i[N-1]):
    count += 1
        
print(count)

Submission status: Wrong Answer

Solution code:
# A - Candy Distribution Again
count = 0
N, x = map(int, input().split())
A = input().split()
A.sort()
A_i = [int(s) for s in A]
if(sum(A_i) == x):
    print(N)
else:
    for i in range(N):
        if(i != N-1):
            x -= A_i[i]
            if(x >= 0):
                count += 1
    print(count)

Submission status: Wrong Answer

Solution code:
# A - Candy Distribution Again
count = 0
N, x = map(int, input().split())
A = input().split()
A.sort()
for i in range(N):
    if(x == 0):
        break
    if(i == N-1):
        #最後なので全部あげる
        if(x == int(A[i])):
            count += 1
    else:
        x -= int(A[i])
        if(x >= 0):
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
# A - Candy Distribution Again
count = 0
N, x = map(int, input().split())
A = input().split()
A.sort()
for i in range(N):
    if(i == N-1):
        #最後なので全部あげる
        if(x == int(A[i])):
            count += 1
    else:
        x -= int(A[i])
        if(x >= 0):
            count += 1
print(count)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a_list = sorted(list(map(int, input().split())))
sum = 0
num = 0

while sum < x and num + 1 <= N:
    sum += a_list[num]
    num += 1
    
print(num)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

a.sort()

sum =x
cnt=0

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

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

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = sorted(list(map(int, input().split())))
if sum(a) < x:
    print(n-1)
    exit()
if sum(a) == x:
    print(n)
    exit()
idx = s = 0
while True:
    s += a[idx]
    if x == s:
        print(idx+1)
        exit()
    if x < s:
        print(max(0, idx-2))
        exit()
    idx += 1

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = sorted(list(map(int, input().split())))
if sum(a) < x:
    print(n-1)
    exit()
if sum(a) == x:
    print(n)
    exit()
idx = s = 0
while True:
    s += a[idx]
    if x == s:
        print(idx+1)
        exit()
    if x < s:
        print(max(0, idx-2))
        exit()

Submission status: Wrong Answer

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

X = 1
ans = 0

while x >= X:
    ans += A.count(X)
    x += -X*(A.count(X))
    X += 1

if ans !=0 & x!=0:
    ans += -1

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

if sum(A) == x:
  print(N)
elif sum(A) < x:
  print(N-1)
else:
  cum = np.cumsum(A)
  if cum[0] > x:
    print(0)
  else:
    k = np.where(cum <= x)[0][0]
    print(k+1)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

if sum(A) == x:
  print(N)
elif sum(A) < x:
  print(N-1)
else:
  cum = np.cumsum(A)
  if cum[0] > x:
    print(0)
  else:
    k = np.where(cum <= x)[0]
    print(k+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)
	exit()

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

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

Submission status: Wrong Answer

Solution code:
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    n,x = I2()
    a = intl()
    a.sort()
    i = 0
    s = 0
    if sum(a) == x:
        print(n)
        exit()
    if sum(a) < x:
        print(n-1)
        exit()
    while s <= x:
        if i == n-1:break
        s += a[i]
        i += 1
    print(i-1)