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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


if x>0 and c>0:
  c-=1

print(c)

Submission status: Wrong Answer

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

A.sort()
S = 0
count = 0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
children = [0] * N
a.sort()
kashi = 0
n = N
if a[0] > x:
    print(0)
elif sum(a) == x:
    print(N)
else:
    for i in range(0,n):
        kashi += a[i]
        children[i] += 1
        if kashi > x:
            kashi -= a[i]
            children[i] -= 1
            break
#     print(kashi)
    if kashi == x:
        print(N - children.count(0))
    else:
        print(N - children.count(0) - 1)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
children = [0] * N
a.sort()
kashi = 0
n = N
if a[0] > x:
    print(0)
elif sum(a) == x:
    print(N)
else:
    while kashi < x:
        for i in range(0,n):
            kashi += a[i]
            children[i] += 1
            if kashi > x:
                kashi -= a[i]
                children[i] -= 1
                break
#        print(kashi)
        n -= 1
        if n < 1:
            break
#    print(children)
    print(N - children.count(0))

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
children = [0] * N
a.sort()
kashi = 0
while kashi < x:
    for i in range(0,N):
        kashi += a[i]
        children[i] += 1
        if kashi > x:
            kashi -= a[i]
            children[i] -= 1
            break
    if kashi == 0:
        break
print(N - children.count(0))

Submission status: Wrong Answer

Solution code:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,x = readInts()
    A = sorted(readInts())
    now = 0
    cnt = 0
    for i in range(n):
        if now + A[i] <= x:
            now += A[i]
            cnt += 1
        else:
            break
    print(cnt)
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
import itertools
import bisect
N,x = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
cumsum = list(itertools.accumulate(A))
ans = bisect.bisect_right(cumsum,x)
print(ans)

Submission status: Wrong Answer

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

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

# 全員に配り終えても余っている場合は、残りのクッキーを1人にわたす
if count == N and 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.sort()

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

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.sort()
ans=0
for a in A:
  x-=a
  if x>=0:
    ans+=1
  else:
    print(ans)
    break

Submission status: Wrong Answer

Solution code:

n,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = []
num = a[0]
i = 1

while num <= x:
    num += a[i]
    if x - a[i] > 0:
        x -= a[i]
        b.append(a[i])
        i += 1
    else:
        b.append(max(0,a[i]))
        break
"""
print(a)
print(b)
print(num)
"""
ans = 0
for i in range(min(len(a),len(b))):
    if a[i] == b[i]:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:

n,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = []
num = a[0]
i = 1

while num <= x:
    num += a[i]
    if x - a[i] > 0:
        x -= a[i]
        b.append(a[i])
        i += 1
    else:
        b.append(max(0,a[i]))
        break

print(a)
print(b)
print(num)

ans = 0
for i in range(min(len(a),len(b))):
    if a[i] == b[i]:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
from bisect import bisect_right
import itertools

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

A.sort()
Acum = list(itertools.accumulate(A))
print(Acum)
answer = bisect_right(Acum,X)
if answer == N:
    if Acum[-1] < X:
        answer -= 1
print(answer)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
n,x=map(int,input().split())
L=sorted(list(map(int,input().split())))
cnt=0
for i in L:
    x-=i
    if n>=0:
        cnt+=1
    else:break
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

else:
    num=N-1
print(num)

Submission status: Wrong Answer

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

else:
    num=N-1
print(num)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
A = list(map(int, input().split()))
cnt = 0
for i in range(N):
  if x < min(A):
    print(cnt)
    break
  elif i == N-1:
    print(N)
  else:
    x -= min(A)
    A.remove(min(A))
    cnt += 1

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
A = list(map(int, input().split()))
cnt = 0
for i in range(N):
  if x < min(A):
    print(cnt)
    break
  elif i == N-1:
    print(cnt+1)
  else:
    x -= min(A)
    A.remove(min(A))
    cnt += 1

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
A = list(map(int, input().split()))
cnt = 0
for i in range(len(A)):
  if x < min(A):
    print(cnt)
    break
  elif i == len(A)-1:
    print(cnt+1)
  else:
    x -= min(A)
    A.remove(min(A))
    cnt += 1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
A = list(map(int, input().split()))
cnt = 0
for i in range(len(A)):
  if x < min(A):
    print(cnt)
    break
  elif i == len(A)-1:
    print(cnt+1)
  else:
    x -= min(A)
    cnt += 1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

cnt = 0
for a in as_:
    if x >= a:
        x -= a
        cnt += 1
    else:
        break

if x > 0 and cnt > 0:
    cnt -= 1

print(cnt)

Submission status: Wrong Answer

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

if X < la[0]:
    print(0)
elif X > sum(la):
    print(N-1)
elif X == sum(la):
    print(N)
else:
    j = 0
    while X > 0:
        X = X - la[j]
        j += 1
    print(j)

Submission status: Wrong Answer

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

print(la)

if X < la[0]:
    print(0)
elif X > sum(la):
    print(N-1)
elif X == sum(la):
    print(N)
else:
    j = 0
    while X > 0:
        X = X - la[j]
        j += 1
    print(j)

Submission status: Wrong Answer

Solution code:
N,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
a_list=a[0]
count=0
for i in range(1,len(a)):
    a_list+=a[i]
    while a_list<=x:
        count+=1
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

input = sys.stdin.readline

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

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

a.sort()

b = 0

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

for i in range(N-1):
    b += a[i]
    if b >= x:
        print(i+1)
        exit()

if (b+a[N-1]) == x:
    print(N)
else:
    print(N-1)

Submission status: Wrong Answer

Solution code:
def resolve():
    n,x=map(int, input().split())
    l=list(map(int, input().split()))
    l.sort()
    num=0
    cnt=0
    if x<l[0]:
        cnt=0
        print(cnt)
    else:
        for i in range(n-1):
            if num<x:
                num+=l[i]
                cnt+=1
        if x-num==l[n-1]:
            cnt+=1
        print(cnt)
resolve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,X=map(int,input().split())
ai=list(map(int,input().split()))
ai.sort()
sum_of_the_candy=0
ans=0
if sum(ai)==X:
	ans=N
elif sum(ai)<X:
	ans=N-1
else:
	for i in range(N):
		sum_of_the_candy=sum_of_the_candy+ai[i]
		if sum_of_the_candy < X:
			ans = ans +1
		else:
			break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
import sys

n, x = map(int, input().split())
a = [int(val) for val in input().split()]

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

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

Submission status: Wrong Answer

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

a.sort()
ans = 0
for ai in a:
    if x - ai < 0:
        break
    x -= ai
    ans += 1
if x > 0:
    ans -= 1
print(ans)

Submission status: Wrong Answer

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

a.sort()
ans = 0
for ai in a:
    if x - ai < 0:
        break
    x -= ai
    ans += 1
    
print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/agc027/tasks/agc027_a
n, x = map(int, input().split())
nums = [int(i) for i in input().split()]
nums.sort()

if sum(nums) == x:
    print(n)
else:
    c = 0
    for i in range(n):
        if x >= nums[i]:
            c += 1
            x -= nums[i]
    if x > 0:
        print(max(0, c - 1))
    else:
        print(c)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/agc027/tasks/agc027_a
n, x = map(int, input().split())
nums = [int(i) for i in input().split()]
nums.sort()
ans = 0
for i in range(n + 1):
    s = sum(nums[:i])
    if s == x:
        ans = max(ans, i)
    elif s < x:
        ans = max(ans, i - 1)
print(ans)

# なんか連続するこどもになっていた

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/agc027/tasks/agc027_a
n, x = map(int, input().split())
nums = [int(i) for i in input().split()]
nums.sort()
ans = 0
for i in range(n):
    for j in range(i, n):
        s = sum(nums[i:j + 1])
        if s == x:
            ans = max(ans, j - i + 1)
        elif s < x:

            ans = max(ans, j - i)

print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/agc027/tasks/agc027_a
n, x = map(int, input().split())
nums = [int(i) for i in input().split()]
nums.sort()
ans = 0
for i in range(n + 1):
    s = sum(nums[:i])
    if s <= x:
        ans = max(ans, i)
print(ans)

Submission status: Wrong Answer

Solution code:
N,X = map(int,input().split(' '))
num_list = list(map(int,input().split(' ')))
num_list_s = sorted(num_list)
total = 0
index = 0
for i in range(N):
    total += num_list_s[i]
    if total > X:
        break
    else:
        index += 1
print(index)

Submission status: Wrong Answer

Solution code:
N,X = map(int,input().split(' '))
num_list = list(map(int,input().split(' ')))
num_list_s = sorted(num_list)
sum = 0
index = 0
for i in range(N):
    sum += num_list_s[i]
    if sum > X:
        break
    else:
        index += 1
print(index)

Submission status: Wrong Answer

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

i = 0
while i < N and x > 0:
    x -= sorted_A[i]
    i += 1

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

Submission status: Wrong Answer

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

    if sum(a) == x:
        print(n)
        exit()

    a.sort()

    ans = 0
    tmp = 0
    for aa in a:
        if tmp < x and aa <= x-tmp:
            tmp += aa
            ans += 1
        if tmp == x:
            print(ans)
            exit()
    if x-tmp > 0:
        ans -= 1

    print(ans)

Submission status: Wrong Answer

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

    if sum(a) == x:
        print(n)
        exit()

    a.sort()

    ans = 0
    tmp = 0
    for aa in a:
        if tmp < x and aa <= x-tmp:
            tmp += aa
            ans += 1
        if tmp == x:
            print(ans)
            exit()
    if ans > 0:
        ans -= 1

    print(ans)

Submission status: Wrong Answer

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

    a.sort()

    ans = 0
    tmp = 0
    for aa in a:
        if tmp < x and aa <= x-tmp:
            tmp += aa
            ans += 1
    if x-tmp > 0 and ans > 0:
        ans -= 1

    print(ans)

Submission status: Wrong Answer

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

a = sorted(a)
ans = 0

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

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

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
A = sorted(list(map(int, input().split())))
l = [0]*N
for i in range(N):
  if X >= A[i]:
    X -= A[i]
    l[i] = A[i]
ans = 0
for i in range(N):
  if A[i] - l[i] == 0:
    ans += 1
if X != 0:
  ans -= 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(max(0,cnt))

Submission status: Wrong Answer

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

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

print(max(0,cnt))

Submission status: Wrong Answer

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

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

print(min(0,cnt))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

a.sort()

ans = 0
i = 0

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

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

print(ans)

Submission status: Wrong Answer

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

a.sort()

ans = 0
i = 0

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

if x != 0:
    ans -= 1

print(ans)

Submission status: Wrong Answer

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

a = sorted(a)

re = x
i = 0
ans = 0

for i in range(N):
    if a[i]<re:
        re -= a[i]
        ans += 1
    else:
        break

if ans==N and re>0:
    ans -= 1

print(ans)

Submission status: Wrong Answer

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

ans=0
for a in a_inputs:
    if a<=x:
        x-=a
        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_inputs = sorted([int(i) for i in input().split()])

ans=0
while a_inputs:
    if a_inputs[0]>x:
        break
    else:
        a = a_inputs.pop(0)
        x-=a
        ans+=1
if x!=0 and ans!=0:
    ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
n, k =map(int,input().split())
data = list(map(int,input().split()))
data = sorted(data)
cnt = 0
for var in data:
    if var < k:
        cnt += 1
        k = k-var
       
    else:
        continue
print(cnt)

Submission status: Wrong Answer

Solution code:
n, k =map(int,input().split())
data = list(map(int,input().split()))
data = sorted(data)
cnt = 0
for var in data:
    if var <= k:
        cnt += 1
        k = k-var
       
    else:
        continue
print(cnt)

Submission status: Wrong Answer

Solution code:
n, k =map(int,input().split())
data = list(map(int,input().split()))
cnt = 0
for var in data:
    if var <= k:
        cnt += 1
        k = k-var
       
    else:
        continue
print(cnt)

Submission status: Wrong Answer

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

i = 0
while len(a) > 0:
    if min(a) > x:
        break
    else:
        x -= min(a)
        a.remove(min(a))
        i += 1
print(i)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Slist = sorted(a)
cnt = 0
Sum = 0

for i in range(len(Slist)):
  Sum += Slist[i]
  if x>=Sum:
    cnt +=1
  else:
    break
print(cnt)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

a.sort()

s = 0
counter = 0

for i in range(N):
    if i != N-1:
        s += a[i]
        if s < x:
            counter += 1
        else:
            break
    else:
        if x - s == a[i]:
            counter += 1
        else:
            break

print(counter)

Submission status: Wrong Answer

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

a.sort()

s = 0
counter = 0

if a[0] <= x:
    for i in range(N):
        if i != N-1:
            if s < x:
                s += a[i]
                counter += 1
            else:
                break
        else:
            if x - s == a[i]:
                counter += 1
            else:
                break

print(counter)

Submission status: Wrong Answer

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

a.sort()

s = 0
counter = 0

for i in range(N):
    if i != N-1:
        if s < x:
            s += a[i]
            counter += 1
        else:
            break
    else:
        if x - s == a[i]:
            counter += 1
        else:
            break

print(counter)

Submission status: Wrong Answer

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

cnt = 0
for i in a:
    if x >= i:
        x -= i
        cnt += 1
    else:
        break
if original != sum(a) and cnt == x:
    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 a:
    if x >= i:
        x -= i
        cnt += 1
    else:
        break
if x != 0 and cnt != 0:
    cnt -= 1

print(cnt)

Submission status: Wrong Answer

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
N,x = map(int,input().split())
arrA = list(map(int,input().split()))
# arrA = np.array(input().split(),dtype=np.int64)

arrA = arrA
arrA.sort()

low,top = 0,N+1

def check(i):
    if sum(arrA[:i]) <= x and i<N+1:
        return True
    return False

while top - low>1:
    half = (top+low)//2
    if check(half):
        low = half
    else:
        top = half

if low == 0:
    ans = 0
elif sum(arrA[:low])==x:
    ans = len(arrA[:low])
else:
    ans = len(arrA[:low])-1
print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Wrong Answer

Solution code:
#coding:utf-8
n, x = map(int, input().split())
a = list(map(int, input().split()))
child = sorted(a)
ans = 0
candy = 0

for i in range(n):
    candy += child[i]
    if candy == x:
        print(i+1)
        exit()
    elif candy > x:
        print(0)
        exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a.sort()
count = 0

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


if i != x+i and count != 0:
    count -= 1

print(count)

Submission status: Wrong Answer

Solution code:
p_c,k_c=(int(x) for x in input().split())
al=list(map(int,input().split()))
al.sort(reverse=True)
count=0
for i in range(p_c):  
  if i==al.index(al[-1]):
    k_c=k_c-al[i]
    if k_c==0:
      count+=1
    else:
      break
  elif k_c==0 or k_c<0:
    break
  else:
    k_c=k_c-al[i]
    count+=1
print(count)

Submission status: Wrong Answer

Solution code:
p_c,k_c=(int(x) for x in input().split())
al=list(map(int,input().split()))
al.sort(reverse=True)
count=0
for i in range(p_c):  
  if i==al.index(al[-1]):
    k_c=k_c-al[i]
    if k_c==0:
      count+=1
    else:
      break
  else:
    k_c=k_c-al[i]
    count+=1
print(count)

Submission status: Wrong Answer

Solution code:
# agc027_a.py
n,x = map(int,input().split())
a = list(map(int,input().split()))
if sum(a) == x:
    print(n)
    exit()

a.sort()
cnt = 0
for i in a:
    if x>=i:
        cnt += 1
        x -= i
print(cnt-1)

Submission status: Wrong Answer

Solution code:
p_c,k_c=(int(x) for x in input().split())
al=list(map(int,input().split()))
al.sort(reverse=True)
count=0
for i in range(p_c):
	k_c=k_c-al[i]
	count+=1
print(count)

Submission status: Wrong Answer

Solution code:
# agc027_a.py
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
print(cnt)

Submission status: Wrong Answer

Solution code:

n,x= map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans= 0

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

if ans == n and 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

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

if X >0 :
    ans -=1     
       
    
print(ans)