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 sys
input = sys.stdin.readline

N,X=map(int,input().split())
vA=list(map(int,input().split()))
vA.sort()

res=0
for a in vA:
	if a<=X:
		res += 1
		X -= a
	else:
		break
if X:
	res = max(0, res-1)

print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

l = sorted(a)
flag = False
for i in range(n):
    x -= l[i]
    if x < 0:
        flag = True
        break
if flag:
    print(i)
else:
    print(n)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n,x,*a=map(int, open(0).read().split())
a.sort()
for i in range(n):
    x-=a[i]
    if x<0:
      print(~-i)
      exit()
    elif x==0:
      print(i)
      exit()
print(n-1)

Submission status: Wrong Answer

Solution code:
n,x,*a=map(int, open(0).read().split())
a.sort()
for i in range(n):
    x-=a[i]
    if x<0:
      print(i)
      exit()
print(n)

Submission status: Wrong Answer

Solution code:
n,x,*a=map(int, open(0).read().split())
a.sort()
i=0
while 0<x:
    x-=a[i]
    if i<~-n:i+=1
    else:break
print(i)

Submission status: Wrong Answer

Solution code:
n,x,*a=map(int, open(0).read().split())
a.sort()
i=0
while 0<x and i<n:
    x-=a[i]
    i+=1
print(~-i)

Submission status: Wrong Answer

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


def solve(N: int, x: int, a: "List[int]"):
    a = sorted(a)

    allocate = [0] * N
    # 配りきる
    while x >= 0 and x >= min(a):
        # 余ったらもっかい
        for i, ai in enumerate(a):
            if ai > x:
                continue
            x -= ai
            allocate[i] += ai

    # 配った値を見る
    ans = 0
    for ai, bi in zip(a, allocate):
        if ai == bi:
            ans += 1

    # 配り切れない場合もある
    if not x == 0:
        print(0)
    else:
        print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, x, a)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


def solve(N: int, x: int, a: "List[int]"):
    a = sorted(a, reverse=True)

    allocate = [0] * N
    # 配りきる
    while x >= 0 and x >= min(a):
        # 余ったらもっかい
        for i, ai in enumerate(a):
            if ai > x:
                continue
            x -= ai
            allocate[i] += ai

    # 配った値を見る
    ans = 0
    for ai, bi in zip(a, allocate):
        if ai == bi:
            ans += 1

    # 配り切れない場合もある
    if not x == 0:
        print(0)
    else:
        print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, x, a)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


def solve(N: int, x: int, a: "List[int]"):
    a = sorted(a, reverse=True)

    allocate = [0] * N
    # 配りきる
    while x >= 0 and x >= min(a):
        # 余ったらもっかい
        for i, ai in enumerate(a):
            if ai > x:
                continue
            x -= ai
            allocate[i] += ai

    # 配った値を見る
    ans = 0
    for ai, bi in zip(a, allocate):
        if ai == bi:
            ans += 1

    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, x, a)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


def main():
    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 i == N - 1 and x > 0:
        ans -= 1

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N, x = [int(x) for x in input().strip().split()]
an = sorted([int(a) for a in input().strip().split()])
cumsum = 0
for i, a in enumerate(an, start=1):
  cumsum += a
  if cumsum > x:
    break
else:
  i += 1
print(i-1)

Submission status: Wrong Answer

Solution code:
N, x = [int(x) for x in input().strip().split()]
an = sorted([int(a) for a in input().strip().split()])
cumsum = 0
for i, a in enumerate(an, start=1):
  cumsum += a
  if cumsum > x:
    break
print(i-1)

Submission status: Wrong Answer

Solution code:
N, x = [int(x) for x in input().strip().split()]
an = sorted([int(a) for a in input().strip().split()])
cumsum = 0
for i, a in enumerate(an, start=1):
  cumsum += a
  if cumsum > x:
    break
print(i)

Submission status: Wrong Answer

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

A.sort()
ans = []
for i in A:
	x -= i
	#print(ans, x)
	if x <= 0:
		break
	ans.append(i)

if x > 0:
	print(len(ans)-1)
else:
	print(len(ans))

Submission status: Wrong Answer

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

A.sort()
ans = []
for i in A:
	ans.append(i)
	x -= i
	#print(ans, x)
	if x <= 0:
		break
if x > 0:
	print(len(ans)-1)
else:
	print(len(ans))

Submission status: Wrong Answer

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

A.sort()
ans = []
for i in A:
	ans.append(i)
	x -= i
	#print(ans, x)
	if x <= 0:
		break

print(len(ans))

Submission status: Wrong Answer

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

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

a.sort()

current = x
result = 0

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

if current > 0 and result != 0:
    result -= 1

print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
al = list(map(int,input().split()))
al.sort()
c = 0
for a in al:
  if x >= a:
    c += 1
    x -= a
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 a:
  if x - i >= 0:
    x -= i
    count += 1
if x > 0 and count != 0  and x > sum(a):
  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
if x > 0 and count != 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 >= 0:
    x -= i
    count += 1
if x > 0:
  count -= 1
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#Candy Distribution Again
n,x = map(int, input().split())
s= list(map(int,input().split()))

s.sort()
s.reverse
if s[0]>x:
    ans=1
else :
    ans=0
for i in s:
    x=x-i
    if x>=0:
        ans+=1
    else :
        break
if x>0:
    ans-=1
    
print(ans)

Submission status: Wrong Answer

Solution code:
#Candy Distribution Again
n,x = map(int, input().split())
s= list(map(int,input().split()))

s.sort()
s.reverse
if s[0]>x:
    ans=1
else :
    ans=0
for i in s:
    x=x-i
    if x>=0:
        ans+=1
    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()))
candies = 0
over = 0
for i in a:
    candies += i
    if x < i:
        over += 1

if candies == x:  # 全員満足
    print(N)
    exit()
elif over == len(a):  # 全員不満足
    print(0)
    exit()
elif candies < x:
    print(N - 1)
    exit()
else:
    print(N - over)
    exit()

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

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

Submission status: Wrong Answer

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

    ans = 0
    num_list.sort()

    for num in num_list:
        if x - num >= 0:
            x -= num
            ans += 1
        else:
            break

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    ans = 0
    num_list.sort()

    for num in num_list:
        if x - num >= 0:
            x -= num
            ans += 1
        else:
            break

    if x != 0:
        ans -= 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans = 0
num_list.sort()

for num in num_list:
    if x - num >= 0:
        x -= num
        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())))
if sum(a)<x:
  print(N-1)
else:
  ans=0
  d=[0]*N
  for i in range(N):
    if x>=a[i]:
      x-=a[i]
      d[i]=1
  ans=d.count(1)
  if x>0:
    print(max(ans-1,0))
  else:
    print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
from itertools import accumulate


N, x = map(int, input().split())
a = list(accumulate(sorted(map(int, input().split()))))
if x in a:
    print(bisect_left(a, x) + 1)
else:
    print(max(0, bisect_left(a, x) - 1))

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
from itertools import accumulate


N, x = map(int, input().split())
a = list(accumulate(sorted(map(int, input().split()))))
if x in a:
    print(bisect_left(a, x) + 1)
else:
    print(bisect_left(a, x) - 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(len(A)):
  if x-A[i]<0:
    break
  else:
    x-=A[i]
print(i)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
import bisect
N, x = map(int, input().split())
a = sorted(list(map(int, input().split())))
c = list(accumulate(a))
ans = bisect.bisect_left(c, x)
if not ans:
  print(ans)
else:
  print(ans if ans != N else ans - 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
N, x = map(int, input().split())
a = sorted(list(map(int, input().split())))
c = list(accumulate(a))
ans = sum([1 for i in c if i <= x])
if not ans:
  print(ans)
else:
  print(ans if x in list(c) else ans - 1)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
N, x = map(int, input().split())
a = sorted(list(map(int, input().split())))
c = accumulate(a)
ans = sum([1 for i in c if i <= x])
print(ans if x in c else 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 a[i] <= x:
        x -= a[i]
        ans += 1
if x != 0:
    ans = max(0, ans - 1)
print(ans)

Submission status: Wrong Answer

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

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

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


    print(ans)

Submission status: Wrong Answer

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

if sum(a) ==x:
    print(n)
else:
    a.sort()
    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()
ans = 0

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


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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007
INF = 122337203685477580

def solve():
    N,x = map(int, input().split())
    vec =list(map(int, input().split())) 
    vec.sort()
    cnt = 0
    index = 0
    while(x > 0 and index < N):
        if(x - vec[index] > 0):
            x -= vec[index]
            cnt += 1
        elif(x - vec[index] == 0):
            cnt += 1
            x -= vec[index]
        else:
            break
        index += 1
        # print(x)
    
    if(x >0):
        cnt -= 1
    if(index == 0):
        cnt = 0
    print(cnt)
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import math


# For taking integer inputs.
def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


N, x = invr()

a = inlist()
a = sorted(a)
c = 0
for i in a:
    if i <= x:
        c += 1
        x -= i
if x > 0 and c > 0:
    c -= 1
print(c)

Submission status: Wrong Answer

Solution code:
import math


# For taking integer inputs.
def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


N, x = invr()

a = inlist()
a = sorted(a)
c = 0
for i in a:
    if i <= x:
        c += 1
        x -= i
if x > 0:
    c -= 1
print(c)

Submission status: Wrong Answer

Solution code:
import math


# For taking integer inputs.
def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


N, x = invr()

a = inlist()
a = sorted(a)
c = 0
for i in a:
    if i <= x:
        c += 1
        x -= i
print(c)

Submission status: Wrong Answer

Solution code:
N,X = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a)
m = sum(a)
count = 0
S=0
if m == X:
    print(N)
elif m < X:
    print(N-1)
elif a[0] > X:
    print(0)
else: 
    for i in a:
        if S < X:
            S = S + i
            count = count + 1
    else:
        print(count-1)

Submission status: Wrong Answer

Solution code:
N,X = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a)
m = sum(a)
count = 0
S=0
if m == X:
    print(N)
elif m < X:
    print(N-1)
elif a[0] > X:
    print(0)
else: 
    for i in a:
        if S < X:
            S = S + i
            count = count + 1
    else:
            print(count)

Submission status: Wrong Answer

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

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 = []

if a[0]>x:
	print(0)
	exit()
elif sum(a)<x:
	print(len(a)-1)

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


print(len(ans))

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 = []

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

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))
elif sum(ans)<x:
	print(len(ans)-1)