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:
A,B = map(int,input().split())
X =list(map(int,input().split()))
X = sorted(X)
count = 0
if B == sum(X):
  print(len(X))
else:
  for i in range(A):
    a = X.pop(0)
    B=B - a
    if B > 0:
      count += 1
  print(count-1)

Submission status: Wrong Answer

Solution code:
A,B = map(int,input().split())
X =list(map(int,input().split()))
X = sorted(X)
count = 0
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:
n, x = map(int, input().split())
a = sorted(list(map(int, input().split())))
ans = 0

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

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

Submission status: Wrong Answer

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

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

print(ans-1)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
N, x=input().split()
N=int(N)
x=int(x)
#x=[]
#y=[]
#t, x, y = [0]*(N+1), [0]*(N+1), [0]*(N+1)#N+1個の空のリストを作成(原点を入れて##るから一つ増える)
#delta_t=0
#delta_x=0
#delta_y=0
#l=0
#t[0],x[0],y[0]=[0, 0, 0]
#とりあえず入力までは完成した．
#for i in range(N):
# t[i+1], x[i+1], y[i+1] = map(int, input().split())
child_i =  list(map(int, input().split()))
#w_len=len(w)
#w_list=list(w)
#print(len(w_list))
#print(w_list)
child_il=sorted(child_i)
#print(child_il)#リストの右端のほうが大きい
i=0
j=0
for i in range(N):
 x=x-child_il[i]
 if x < 0:
    print(j)
    sys.exit()
 else:
     j=j+1

print(j)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:


def main()->None:
    (N, x) = map(int, input().split())
    a = list(map(int, input().split()))
    sorted_a = sorted(a) # 小さい順にならべる
    count = 0
    for i in sorted(a):
        x -= i
        if x < 0:
            break
        count += 1
    if count < N:print(count)
    else: print(N-1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:


def main()->None:
    (N, x) = map(int, input().split())
    a = list(map(int, input().split()))
    sorted_a = sorted(a) # 小さい順にならべる
    count = 0
    for i in sorted(a):
        x -= i
        if x < 0:
            break
        count += 1
    if count <= N:print(count)
    else: print(N-1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:


def main()->None:
    (N, x) = map(int, input().split())
    a = list(map(int, input().split()))
    sorted_a = sorted(a) # 小さい順にならべる
    count = 0
    for i in sorted(a):
        x -= i
        if x < 0:
            break
        count += 1
    if count <= N:print(count)
    else: print(N)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:


def main()->None:
    (N, x) = map(int, input().split())
    a = list(map(int, input().split()))
    sorted_a = sorted(a) # 小さい順にならべる
    count = 0
    for i in sorted(a):
        x -= i
        if x < 0:
            break
        count += 1
    if count < N:print(count)
    else: print(N)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:


def main()->None:
    (N, x) = map(int, input().split())
    a = list(map(int, input().split()))
    sorted_a = sorted(a) # 小さい順にならべる
    count = 0
    for i in sorted(a):
        x -= i
        if x < 0:
            break
        count += 1
    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:


def main()->None:
    (N, x) = map(int, input().split())
    a = list(map(int, input().split()))
    sorted_a = sorted(a) # 小さい順にならべる
    count = 0
    for i in sorted(a):
        x -= i
        if x < 0:
            break
        else:
            count += 1
    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:


def main()->None:
    (N, x) = map(int, input().split())
    a = list(map(int, input().split()))
    sorted_a = sorted(a) # 小さい順にならべる
    count = 0
    for i in sorted(a):
        x -= i
        if x <= 0:
            break
        else:
            count += 1
    print(count)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
child = sorted(list(map(int, input().split())))
count = 0

for i in range(a - 1):
    if b >= child[i]:
        b -= i
        count += 1
if b == child[-1]:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
child = sorted(list(map(int, input().split())))
count = 0
print(child)

for i in range(a - 1):
    if b >= child[i]:
        b -= i
        count += 1
if b == child[-1]:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
child = sorted(list(map(int, input().split())))
count = 0
for i in child:
    if b >= i and i != child[-1]:
        b -= i
        count += 1
    elif i == child[-1] and b == i:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
child = list(map(int, input().split()))
count = 0
for i in child:
    if b >= i and i != child[-1]:
        b -= i
        count += 1
    elif i == child[-1] and b == i:
        count += 1
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

res = [sum(a[:i+1]) for i in range(len(a))]
index = bisect.bisect_left(res, x)

if index == len(res):
    print(index-1)
elif index == 0:
    if res[index] == x:
        print(index+1)
    else:
        print(index)
else:
    print(index+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a_s = map(int, input().split())
sorted_a_s = sorted(a_s)
rest_snaks = x
satisfied_num = 0
for n in range(N):
    if sorted_a_s[n] <= rest_snaks:
        if n == (N-1):
            if rest_snaks == 0:
                satisfied_num += 1
        else:
            satisfied_num += 1
        rest_snaks -= sorted_a_s[n]
    else:
        rest_snaks = 0

print(satisfied_num)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a_s = map(int, input().split())
sorted_a_s = sorted(a_s)
rest_snaks = x
satisfied_num = 0
for n in range(N):
    if sorted_a_s[n] <= rest_snaks:
        if n == N-1:
            if rest_snaks == 0:
                satisfied_num += 1
        else:
            satisfied_num += 1
        rest_snaks -= sorted_a_s[n]
    else:
        rest_snaks = 0

print(satisfied_num)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a_s = map(int, input().split())
sorted_a_s = sorted(a_s)
rest_snaks = x
satisfied_num = 0
for n in range(N):
    if sorted_a_s[n] <= rest_snaks:
        satisfied_num += 1
        rest_snaks -= sorted_a_s[n]
    else:
        rest_snaks = 0

print(satisfied_num)

Submission status: Wrong Answer

Solution code:
# AGC027
N, x = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
ans = 0
cnt = 0
if x > sum(A):  #お菓子が多い時は最後の一人に残った分をあげる
    print(N-1)
    exit()
if x == sum(A): # ちょうどのとき
    print(N)
    exit()
# 少ない時
for i in range(N):
    cnt += A[i]
    if x < cnt:
        ans = i-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
sumOf = 0
for i in a:
    sumOf += i
    if sumOf > x:
        break
    ans += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import heapq
import sys
from collections import Counter

#N,K=map(int, input[0].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#x=list(map(int, input[1].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

N,x=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
a=list(map(int,input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

heapq.heapify(a)  # リストを優先度付きキューへ

for i in range(N):
    x-=heapq.heappop(a)  # 最小値の取り出し
    print(x,a)
    if x<=0 or i==N-1:
        if x==0:
            print(i+1)
        else:
            print(i)
        break

Submission status: Wrong Answer

Solution code:
import math
import heapq
import sys
from collections import Counter

#N,K=map(int, input[0].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#x=list(map(int, input[1].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

N,x=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
a=list(map(int,input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

heapq.heapify(a)  # リストを優先度付きキューへ

for i in range(N):
    x-=heapq.heappop(a)  # 最小値の取り出し
    #print(x,a)
    if x<=0 or i==N-1:
        print(i+1)
        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(n):
    if x>=a[i]:
        ans+=1
        x-=a[i]
    else:
        break
    if n-1==i:
        if a[i]<x:
            continue
        else:
            ans+=1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,x = inpl()
a = inpl()
a.sort()
if a[0] > x:
    print(0)
elif sum(a) == x:
    print(n)
elif sum(a) > x:
    print(n-1)
else:
    s = 0
    for i,y in enumerate(a):
        if s + y <= x:
            s += y
        else:
            print(i)
            break
    else:
        print(n-1)

Submission status: Wrong Answer

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

count = 0
for i in sorted(a):
    if x >= i:
        x -= i
        count += 1
    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(map(int, input().split()))

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def main():
    N, x = (int(i) for i in input().split())
    a = [int(i) for i in input().split()]
    a.sort()
    ans = 0
    i = 0
    while x > 0:
        if i < N and x - a[i] >= 0:
            x -= a[i]
            ans += 1
        else:
            break
        i += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

a.sort()

ans=0
tmp=0
for i in  range(len(a)):
  tmp+=int(a[i])

if tmp==x:
  print(N)
  exit()

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

if tmp!=x:
  print(ans)

Submission status: Wrong Answer

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

a.sort()

ans=0
tmp=0
for i in  range(len(a)):
  tmp+=int(a[i])

if tmp==x:
  print(N)
  exit()

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

Submission status: Wrong Answer

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

a.sort()

ans=0
tmp=0
for i in  range(len(a)):
  tmp+=int(a[i])

if tmp==x:
  print(N)
  exit()

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

Submission status: Wrong Answer

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

a.sort()

ans=0
tmp=0
for i in  range(len(a)):
  tmp+=int(a[i])

if tmp==x:
  print(N)
  exit()

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

Submission status: Wrong Answer

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

A.sort()
s = 0
ans = 0
while ans < n and s <= x:
    s += A[ans]
    ans += 1

if s > x:
    ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
N, X = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
last_index = len(A) - 1
ret = 0
for i, a in enumerate(A):
    if a < X and i == last_index:
        ret = N - 1
    else:
        ret += 1
        X -= a
print(ret)

Submission status: Wrong Answer

Solution code:
N, X = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
last_index = len(A) - 1
ret = 0
for i, a in enumerate(A):
    if a <= X:
        if i == last_index and X > 0:
            continue
        ret += 1
        X -= a
print(ret)

Submission status: Wrong Answer

Solution code:
N, X = list(map(int, input().split()))
A = list(map(int, input().split()))
ret = 0
for a in A:
    if a <= X:
        ret += 1
        X -= a
print(ret)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in a:
    sum += i
    people += 1
    if sum >= x:
        break

if sum < x:
    people -= 1
elif x < min(a):
    people = 0

print(people)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
sum = 0
count = 0
while True:
  sum += a[0]
  if sum > x:
    break
  count += 1
  del a[0]
  if len(a) == 0:
    break
print(count)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
sum = 0
count = 0
while True:
  if sum > x or len(a) == 0:
    break
  sum += a[0]
  count += 1
  del a[0]
print(count)

Submission status: Wrong Answer

Solution code:
N, x = tuple(map(int, input().split()))
A = list(map(int, input().split()))
count = 0
for a in A[:-1]:
    if a <= x:
        count += 1
        x -= a

if A[-1] == x:
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
cnt = 0
while x != 0:
    for i in l:
        if x >= i:
            x -= i
            cnt += 1
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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

d.sort()
happy = 0

for i in range(N):
    x = x - d[i]
    if i == len(d)-1:
        break
    if x < 0:
        break
    else:
        happy += 1

print(happy)

Submission status: Wrong Answer

Solution code:
import sys

#ｘは持っている飴のこすう
n,x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0


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

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


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

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


a.sort()

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

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

Submission status: Wrong Answer

Solution code:
def solve(n, x, a):
    ans = 0
    for v in sorted(a):
        if v <= x:
            ans += 1
            x -= v
    if x > 0 and ans > 0:
        ans -= 1
    return ans

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

Submission status: Wrong Answer

Solution code:
def solve(n, x, a):
    ans = 0
    for v in sorted(a):
        if v <= x:
            ans += 1
            x -= v
    return ans if (x <= 0) else ans - 1

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

Submission status: Wrong Answer

Solution code:
def solve(n, x, a):
    ans = 0
    for v in sorted(a):
        if v <= x:
            ans += 1
            x -= v
    return ans

n, x = 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()
ans = 0
for i in a:
  if x >= i:
    x -= i
    ans += 1
if x == 0:
  print(ans)
else:
  print(min(N - 1, x))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
an = list(map(int, input().split()))
an.sort()
flag = [0]*N
count = 0
i = 0
xs = x
if an[0] < x:
  while x > 0:
    if x >= an[i]:
      x -= an[i]
      if flag[i] == 0:
        flag[i] += 1
        count += 1
      elif flag[i] == 1:
        flag[i] += 1
        count -= 1
        i = 0
      else:
        i = 0
    i += 1
    if i >= N:
      i = 0
print(count)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
an = list(map(int, input().split()))
an.sort()
flag = [0]*N
count = 0
i = 0
xs = x
while(1):
  if x >= an[i]:
    x -= an[i]
    if flag[i] == 0:
      flag[i] += 1
      count += 1
    elif flag[i] == 1:
      flag[i] += 1
      count -= 1
      i = 0
    else:
      i = 0
  if x == 0:
    break
  i += 1
  if i >= N:
    i = 0
    if xs == x:
      break
print(count)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
an = list(map(int, input().split()))
an.sort()
flag = [0]*N
count = 0
i = 0
xs = x
while(1):
  if x >= an[i]:
    x -= an[i]
    if flag[i] == 0:
      flag[i] += 1
      count += 1
    elif flag[i] == 1:
      flag[i] += 1
      count -= 1
      i = 0
  if x == 0:
    break
  i += 1
  if i >= N:
    i = 0
    if xs == x:
      break
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

count = 0
array = sorted(array, reverse=True)
for i in range(n):
    x = x - array[i]
    if x >= 0:
        count += 1
    else:
        break
if x > 0:
    count -= 1
print(count)

Submission status: Wrong Answer

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

count = 0
array = sorted(array, reverse=True)
for i in range(n):
    x = x - array[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()))
aa = sorted(a)
nokori = x
cnt = 0
if x > sum(a):
         print(n-1)
else:
         for i in range(n):
                  if nokori >= a[i]:
                           cnt +=1
                           nokori = nokori - a[i]
         print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():

    n, x = map(int, input().split())
    a = sorted(list(map(int, input().split())))
    if a[0] > x:
        print(0)
        exit()
    ans = 0
    for i in range(n):
        if x >= a[i]:
            x -= a[i]
            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())
a = list(map(int, input().split()))
a.sort()
cnt = 0
for i in range(n):
  if a[i] <= x:
    x -= a[i]
    cnt += 1
  else:
    break
if x >= a[0]:
  cnt -= 1
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 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()))
a.sort()
cnt = 0
for i in range(n):
  if a[i] <= x:
    x -= a[i]
    cnt += 1
  else:
    break
print(cnt)