Problem:


Score : 200 points

Problem Statement

There are N children, numbered 1, 2, ..., N.

Snuke has decided to distribute x sweets among them.
He needs to give out all the x sweets, but some of the children may get zero sweets.

For each i (1 \leq i \leq N), Child i will be happy if he/she gets exactly a_i sweets.
Snuke is trying to maximize the number of happy children by optimally distributing the sweets.
Find the maximum possible number of happy children.

Constraints

All values in input are integers.

2 \leq N \leq 100

1 \leq x \leq 10^9

1 \leq a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N x
a_1 a_2 ... a_N

Output

Print the maximum possible number of happy children.

Sample Input 1

3 70
20 30 10

Sample Output 1

2

One optimal way to distribute sweets is (20, 30, 20).

Sample Input 2

3 10
20 30 10

Sample Output 2

1

The optimal way to distribute sweets is (0, 0, 10).

Sample Input 3

4 1111
1 10 100 1000

Sample Output 3

4

The optimal way to distribute sweets is (1, 10, 100, 1000).

Sample Input 4

2 10
20 20

Sample Output 4

0

No children will be happy, no matter how the sweets are distributed.



Sample input:
3 70
20 30 10


Sample output:
2

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = [int(input()) for i in range(n)]
    #a = list(map(int, input().split()))
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    n,x=map(int,input().split())
    a=sorted(map(int,input().split()))
    cnt = 0
    suma = sum(a)
    if suma < x:
        print(n-1)
    elif suma == x:
        print(n)
    else:
        for i in a:
            if x <= i:
                break
            cnt+=1
            x-= i
        print(cnt)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = [int(input()) for i in range(n)]
    #a = list(map(int, input().split()))
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    n,x=map(int,input().split())
    a=sorted(map(int,input().split()))
    cnt = 0
    suma = sum(a)
    if suma < x:
        print(n-1)
    elif suma == x:
        print(n)
    else:
        for i in a:
            if x <=0:
                break
            cnt+=1
            x-= i
        print(cnt)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = [int(input()) for i in range(n)]
    #a = list(map(int, input().split()))
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    n,x=map(int,input().split())
    a=sorted(map(int,input().split()))
    xx = x
    cnt = 0
    suma = sum(a)
    if suma > x:
        print(n-1)
    elif suma == x:
        print(n)
    else:
        for i in a:
            cnt+=1
            xx-= i
            if xx <=0:
                break
        print(cnt)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = [int(input()) for i in range(n)]
    #a = list(map(int, input().split()))
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    n,x=map(int,input().split())
    a=sorted(map(int,input().split()))
    xx = x
    cnt = 0
    suma = sum(a)
    if suma < x:
        print(n-1)
    elif suma == x:
        print(n)
    else:
        for i in a:
            cnt+=1
            xx-= i
            if xx <=0:
                break
        print(cnt)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
N, x = map(int, input().split())
a = sorted(map(int, input().split()))
ans = 0
score_x  = x

if score_x < a[0]:
    print(0)
    sys.exit()
    
for  i in range(N):
    if i == (N-1):
        if a[i] == score_x:
            ans = ans + 1
        else:
            break      
    if score_x  >= a[i]:
        score_x = (score_x - a[i])
        ans = ans + 1


print(ans)

Submission status: Wrong Answer

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


ans = 0
score_x  = x

if score_x < a[0]:
    print(0)
    sys.exit()
    
for  i in range(N):

    if score_x  >= a[i]:
        score_x = (score_x - a[i])
        ans = ans + 1


print(ans)

Submission status: Wrong Answer

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

ans = 0
score_x  = x

for  i in range(N):
    if score_x < a[i]:
        print(0)
        sys.exit()

    elif score_x  >= a[i]:
        score_x = (score_x - a[i])
        ans = ans + 1

print(ans)

Submission status: Wrong Answer

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

ss = list(map(int, input().split(' ')))
    
r = x
count = 0    
for s in sorted(ss):
    if r - s < 0:
        break
    else:
        r -= s
        count += 1
if r > 0 and count > 0:
    count -= 1
print(count)

Submission status: Wrong Answer

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

ss = list(map(int, input().split(' ')))
    
r = x
count = 0    
for s in sorted(ss):
    if r - s < 0:
        break
    else:
        r -= s
        count += 1
print(count)

Submission status: Wrong Answer

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

answer = 0
id = -1

for idx, a in enumerate(sorted(li_a)):
    id = idx
    if x >= a:
        answer += 1
        x -= a
    else:
        break
if x == 0 or answer == 0:
    print(answer)
else:
    if id == (n -1):
        print(answer - 1)
    else:
        print(answer)

Submission status: Wrong Answer

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

answer = 0

for a in sorted(li_a):
    if x >= a:
        answer += 1
        x -= a
    else:
        break
print(answer if (x == 0 or answer == 0) else answer - 1)

Submission status: Wrong Answer

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

dat.sort()
for i in range(n):
    if x >= dat[i]:
        res += 1
        x -= dat[i]
    else:
        break
if x > 0 and res != 0:
    res -= 1
print(res)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
res = 0
dat = list(map(int, input().split()))
dat.sort()
for i in range(n):
    if x >= dat[i]:
        res += 1
        x -= dat[i]
if x > 0 and res != 0:
    res -= 1
print(res)

Submission status: Wrong Answer

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

ans=0
i=0
while A[i]<=n:
  ans+=1
  i+=1
  if i==N:
    break
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-


#----------
n,x = list(map(int, input().rstrip().split()))
a_list = list(map(int, input().rstrip().split()))
#----------
a_list.sort()

x_remain=x
result = -1
for i in range(n):
    x_remain -= a_list[i]
    
    if x_remain < 0:
       result = i
       break

if result == -1 :
    result = n

print(result)

Submission status: Wrong Answer

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

for i in range(0, N):
	x -= a_new[i]
	if x < 0:
		index = i - 1
		break
	if x == 0:
		index = i + 1
		break
	index = i

if index < 0:
	index = 0

print(str(index))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def main():
    N, x = map(int, input().split())
    a_list = list(map(int, input().split()))
    ans = 0
    for a in sorted(a_list):
        if a <= x:
            ans += 1
            x -= a
        else:
            break
    if ans == N:
        print(ans - 1)
    else:
        print(ans)

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 = list(map(int, input().split()))
    for i, a in enumerate(sorted(a_list), start=1):
        x -= a
        if x < 0:
            break
    if x >= 0:
        print(i)
    else:
        print(i-1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

list_a.sort()
total = sum(list_a)
if x < list_a[0] :
    print(0)
    exit()

ans = 0

for i in range(N) :
    if list_a[i] <= x :
        x -= list_a[i]
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def main():
    N, x = map(int, input().split())
    a_list = list(map(int, input().split()))
    if sum(a_list) == x:
      print(N)
      sys.exit()
    for i, a in enumerate(sorted(a_list), start=1):
        x -= a
        if x < 0:
            break
    if x >= 0:
        print(i)
    else:
        print(i-1)

Submission status: Wrong Answer

Solution code:
[N, x] = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
count = 0
i = 0
while x >= 0 and i <= len(a):
  x -= a[i]
  if i == len(a)-1:
    if x != a[i]:
      break
  if x >= 0:
    count += 1
  i += 1
  
print(count)

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())))
A = list(accumulate(A))
ind = bisect.bisect_right(A,x)-1
if ind == -1:
    print(0)
else:
    print(ind+1)

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())))
A = list(accumulate(A))
ind = bisect.bisect_right(A,x)-1
if ind == -1:
    print(0)
elif A[ind] == x:
    print(ind+1)
else:
    print(ind)

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())))
A = list(accumulate(A))
ind = bisect.bisect_right(A,x)-1
if A[ind] == x:
    print(ind+1)
else:
    print(ind)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

lst.sort(reverse = True)
cnt = 0

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

Submission status: Wrong Answer

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

lst.sort(reverse = True)
cnt = 0

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

Submission status: Wrong Answer

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

lst.sort(reverse = True)
cnt = 0

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

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = [int(_) for _ in input().split()]
a.sort()
ans = 0
for i in a:
    if x < i:
        break
    x -= i
    ans += 1
if x > 0 and ans != 0:
    ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
try:
  N, x = map(int, input().split())
  a = list(map(int, input().split()))
  a_ = sorted(a)
  cnt = 0
  for i in a_:
      if i<=x:
          cnt += 1
          x = x-i
  print(cnt)
except EOFError:
  pass

Submission status: Wrong Answer

Solution code:
try:
  N, x = map(int, input().split())
  a = list(map(int, input().split()))
  a_ = sorted(a)
  cnt = 0
  for i in a_:
      if i<=x:
          cnt += 1
          x = x-i
      else:
          break
  print(cnt)
except EOFError:
  pass

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
try:
    N, x = map(int, input().split())
    l = list(map(int, input().split()))
    l_ = sorted(l)
    cnt = 0
    for i in l_:
        _ = x-i
        if _>= 0:
            cnt += 1
        if _<0:
            break
    print(cnt)
except EOFError:
    pass

Submission status: Wrong Answer

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

children.sort()
cnt = 0

for i in children:
    if x - i < 0:
        break
    elif i == children[N - 1] and x - i > 0:
        print(N - 1)
    else:
        x -= i
        cnt += 1

print(cnt)

Submission status: Wrong Answer

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

children.sort()
sum = 0

for i in range(N):
    sum += children[i]
    if sum >= x:
        print(i + 1)
        break
    elif i == N - 1:
        print(N - 1)

Submission status: Wrong Answer

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

children.sort()
sum = 0

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

Submission status: Wrong Answer

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

children.sort()
cnt = 0

for i in children:
    if x - i < 0:
        break
    else:
        x -= i
        cnt += 1

print(cnt)

Submission status: Wrong Answer

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

children.sort()
cnt = 0

for i in children:
    cnt += 1
    if x - i < 0:
        break
    else:
        x -= i

print(cnt)

Submission status: Wrong Answer

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

children.sort()
cnt = 0

for i in children:
    if x - i < 0:
        break
    else:
        x -= i
        cnt += 1
        
print(cnt)

Submission status: Wrong Answer

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

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

if x > 0:
    c -= 1

print(c)

Submission status: Wrong Answer

Solution code:
def solve(n, x, A):
    A.sort()
    count = 0
    for a in A:
        if a <= x:
            x -= a
            count += 1
        else:
            break
    return count

_n, _x = list(map(int, input().split()))
_A = list(map(int, input().split()))
print(solve(_n, _x, _A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
c,i=0,0
while(i<n and x>0):
  if a[i]<=x:
    x-=a[i]
    c+=1
    i+=1
  else:
    break
  if i==n-1 and x!=0:
    c-=1
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
array = list(map(int, input().split()))
array = sorted(array, reverse=False)
if sum(array) <= x:
  print(N)
elif array[0] > x:
  print(0)
for i in range (N):
  if sum(array[0:i]) >= x:
    print(i)
    break

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(len(A)):
    x = x-A[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( )))

a.sort()
tmp = a[0]
cnt = 0
for i in range(1,n):
    #print(cnt,tmp)
    if tmp<=x:
        cnt += 1
        tmp += a[i]
    else:
        break
    
print(cnt)

Submission status: Wrong Answer

Solution code:
import itertools
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
a = list(itertools.accumulate(a))
cnt=0
for i in range(n):
    if i==n-1 and a[-1]!=x:
        pass
    elif a[i]<=x:
        cnt+=1
        if a[i]==x:
            break
print(cnt)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
a.append(-float('inf'))

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

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

print(count)

Submission status: Wrong Answer

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

# 小さい数から配っていくと子供の人数を最大化できる
a = sorted(a)

leftCandy = 0
childrenCnt = 0
for i in range(len(a)):
  leftCandy = x - a[i]
  if leftCandy >= 0:
    childrenCnt += 1

if leftCandy > 0:
  childrenCnt -= 1

print(childrenCnt)

Submission status: Wrong Answer

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

# 小さい数から配っていくと子供の人数を最大化できる
a = sorted(a)

leftCandy = 0
childrenCnt = 0
for i in range(len(a)):
  leftCandy = x - a[i]
  if leftCandy >= 0:
    childrenCnt += 1

if leftCandy > 0:
  print(N-1)
else:
  print(childrenCnt)

Submission status: Wrong Answer

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

# 小さい数から配っていくと子供の人数を最大化できる
a = sorted(a)

leftCandy = 0
childrenCnt = 0
for i in range(len(a)):
  leftCandy = x - a[i]
  if leftCandy >= 0:
    childrenCnt += 1

print(childrenCnt)

Submission status: Wrong Answer

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

cont = 0

for y in sorted(a):
    if x >= y:
        cont += 1
        x -= y

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

Submission status: Wrong Answer

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

cont = 0

for i in sorted(a):
    x -= i
    if x >= 0:
        cont += 1
    else:
        break

if x != 0:
    cont -= 1

print(cont)

Submission status: Wrong Answer

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

cont = 0

for i in sorted(a):
    x -= i
    if x >= 0:
        cont += 1

if x != 0:
    cont -= 1

print(cont)

Submission status: Wrong Answer

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

cont = 0

for i in sorted(a):
    x -= i
    if x > 0:
        cont += 1
    else:
        break

if x != 0:
    cont -= 1
    
print(cont)

Submission status: Wrong Answer

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

cont = 0

for y in sorted(a):
    if x >= y:
        cont += 1
        x -= y

if x != 0:
    cont = cont-1
print(cont)

Submission status: Wrong Answer

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

sorted_a = sorted(a)
cont = 0

for i in range(N):
    if x >= sorted_a[i]:
        cont += 1
        x = x - sorted_a[i]
if x != 0:
    cont = cont -1
print(cont)

Submission status: Wrong Answer

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

cont = 0

for y in sorted(a):
    if x >= y:
        cont += 1
        x -= y
print(cont)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n, x = LI()
    a = LI()
    a.sort()
    ans = 0
    for ai in a:
        x -= ai
        if x < 0:
            break
        ans += 1
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n, x = LI()
    a = LI()
    a.sort()
    a = itertools.accumulate(a)
    ans = 0
    for ai in a:
        if ai > x:
            break
        ans += 1
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n, x = LI()
    a = LI()
    a = itertools.accumulate(a)
    ans = 0
    for ai in a:
        if ai > x:
            break
        ans += 1
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_right

N, x, *A = map(int, open(0).read().split())

A.sort()
S = list(accumulate(A))

if S[-1] == x:
    print(N)
else:
    k = bisect_right(A, x)
    print(N - 1 if k == N else k)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_right

N, x, *A = map(int, open(0).read().split())

A.sort()
S = list(accumulate(A))

if S[-1] == x:
    print(N)
else:
    print(min(N - 1, bisect_right(A, x)))

Submission status: Wrong Answer

Solution code:
from sys import stdin
import itertools
#stdin = open("input.txt")

if __name__ == "__main__":
    N, K = [int(item) for item in stdin.readline().split()]
    li = [int(item) for item in stdin.readline().split()]
    
    li.sort()
    a = [item for i, item in enumerate(itertools.accumulate(li)) if item <= K]
    print(len(a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N, x =  map(int, input().split(' '))
A = list(map(int, input().split(' ')))
A.sort()

def dfs(i, rest, ret):
    if i == N:
        return ret
    else:
        if A[i] <= rest:
            return max(dfs(i+1, rest - A[i], ret + 1), dfs(i+1, rest, ret))
        else:
            return ret

ans = dfs(0, x, 0)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
for i in a:
    x -= i
    if x >= 0:
        ans += 1

print(ans)

Submission status: Wrong Answer

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

count = 0
for i in range(a):
  x -= chil[i]
  if x >= 0:
    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()
candy = 0
if x <= a[0]:
    print(0)
    exit(0)
for i in range(n):
    candy += a[i]
    if candy >=x:
        print(i+1)
        exit(0)
if i == n-1:
    print(n-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

count = 0
for i, a in enumerate(sorted(A)):
    if X >= a:
        count += 1
        X -= a
    
    if i == N - 1 and X > 0:
        count -= 1

print(count)

Submission status: Wrong Answer

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

count = 0
for a in sorted(A):
    if X >= a:
        count += 1
        X -= a

print(count)

Submission status: Wrong Answer

Solution code:
A,B = map(int,input().split())
X =list(map(int,input().split()))
X = sorted(X)
count = 0
j=len(X)
if B == sum(X):
  print(len(X))
elif B <= min(X):
  print(0)
else:
  for i in range(A):
    a = X.pop(0)
    B=B - a
    if B >= 0:
      count += 1
    if B >= 0 and count == j:
      count = count -1
  print(count)

Submission status: Wrong Answer

Solution code:
A,B = map(int,input().split())
X =list(map(int,input().split()))
X = sorted(X)
count = 0
if B == sum(X):
  print(len(X))
elif B <= min(X):
  print(0)
else:
  for i in range(A):
    a = X.pop(0)
    B=B - a
    if B >= 0:
      count += 1
  print(count)

Submission status: Wrong Answer

Solution code:
A,B = map(int,input().split())
X =list(map(int,input().split()))
X = sorted(X)
count = 0
if B == sum(X):
  print(len(X))
elif B <= min(X):
  print(0)
else:
  for i in range(A):
    a = X.pop(0)
    B=B - a
    if B > 0:
      count += 1
  print(count-1)