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()

b = []
for i in range(N):
    b.append(i)
c = 0
d = 0
for i in range(N):
    b[i] = d
    for j in range(N):
        d += a[j]
for i in range(N):
    if b[i] <= X:
        c += 1
print(c)

Submission status: Wrong Answer

Solution code:
from numpy import *

N,x=map(int,input().split())
a=zeros(N)
a=[int(i) for i in input().split()]

a.sort()
count=0
res=0
for i in range(N):
    res+=a[i]
    if(res>x):
        break
    else:
        count+=1
print(count)

Submission status: Wrong Answer

Solution code:
#入力
#3 70
#20 30 10

N,x = map(int,input().split())
a = [int(i) for i in input().split()]
a.sort()
#print(a)
happy=0
for i in range(N):
    if x >= a[i]:#菓子の数が欲しがる数が最小よりすくないなら終了
        x = x-a[i]#必要数が少ない人からあげてく，菓子の残数が減る
        happy = happy+1
        if x <= 0:#菓子がなくなれば終わり
            break
    else:
        break
if x > 0:
    happy = happy-1
print(max(happy,0))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a.sort()
x_tmp = x
delighted_num = 0

for ax in a:
    if x_tmp >= ax:
        x_tmp = x_tmp - ax
        delighted_num += 1
if x_tmp > 0 and delighted_num > 0:
    delighted_num -= 1
print(delighted_num)

Submission status: Wrong Answer

Solution code:
#入力
#3 70
#20 30 10

N,x = map(int,input().split())
a = [int(i) for i in input().split()]
a.sort()
#print(a)
happy=0
for i in range(N):
    if x >= a[i]:#菓子の数が欲しがる数が最小よりすくないなら終了
        x = x-a[i]#必要数が少ない人からあげてく，菓子の残数が減る
        happy = happy+1
        if x <= 0:#菓子がなくなれば終わり
            break
    else:
        if x != 0:
            happy = happy-1
            break
if x > 0:
    happy = happy-1
print(max(happy,0))

Submission status: Wrong Answer

Solution code:
import sys


# n = int(sys.stdin.readline().strip())
#
# line = sys.stdin.readline().strip()
# values = list(map(int, line.split()))


def main():
    line = sys.stdin.readline().strip()
    values = list(map(int, line.split()))
    N, x = values[0], values[1]
    line = sys.stdin.readline().strip()
    values = list(map(int, line.split()))
    d = {}

    def rec(i, j):
        res = 0
        if (i, j) in d:
            return d[(i, j)]
        if i == N:
            if j == 0:
                return 0
            else:
                return -1
        elif j < values[i]:
            res = rec(i + 1, j)
        else:
            res = max(rec(i + 1, j), rec(i + 1, j - values[i]) + 1)
        d[(i, j)] = res
        return res

    res = rec(0, x)
    if res == -1:
        print(0)
    else:
        print(res)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(N):
    x -= a[i]
    if 0 < x:
        count += 1
        if a[i] == a[-1]:
            count -= 1
    if x == 0:
        count += 1
        break
print(count)

Submission status: Wrong Answer

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

b = []
for i in range(N):
    b.append(i)
c = 0
for i in range(N):
    b[i] = 0
    for i in range(N):
        b[i] += a[i]
for i in range(N):
    if b[i] <= X:
        c += 1
print(c)

Submission status: Wrong Answer

Solution code:
import numpy

N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
a_sum = numpy.cumsum(a)
ans = numpy.sum(a_sum <= x)

print(ans)

Submission status: Wrong Answer

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

li = input().split()
k = int(li[1])
print(k)
del li[:2]
li.sort()
j = 0
t = 0
for i in li:
    k -= int(i)
    print(k)
    if k == 0:
        t += 1
        break
    elif k < 0:
        t += 1
        break
    else:
        t += 1
if not k == 0:
    t -= 1

print(t)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
A = [int(x) for x in input().split()]
count = 0
def Candy (i, rest, count):

    #最後に余った
    if i == N and rest > 0:
        if count > 0:
            return count - 1
        else:
            return count

    #最後に余らなかった
    if i >= N:
        return count   
    #配って次へ
    if rest >= A[i]:
        rest -= A[i]
        count += 1
        return Candy(i+1, rest, count)

    #配らないで次へ
    
    return Candy(i+1, rest, count)

print(Candy(0, X, count))

Submission status: Wrong Answer

Solution code:

N, V = list(map(int, input().split()))
C = list(map(int, input().split()))
C = [c for c in C if c<=V]
N = len(C)


W = [1 for i in range(N)]
F = [0 for i in range(V+1)]

def pack01(F, c, w):
    """
    f: states
    c: cost
    w: value

    v: volume
    """
    for v in range(c, V+1)[::-1]:
        F[v] = max(F[v], F[v-c]+w)
for i in range(N):
    pack01(F, C[i], W[i])

s = sum(C)
if s==V or s>V:
    print(F[-1])
elif sum(C)<V:
    print(F[-1]-1)

Submission status: Wrong Answer

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

li = 0
li = list(map(int,input().split()))



j = 0
k = 0
while k < N - 1:
    if x > li[k]:
        j += 1
        x = x - li[k]
        k += 1
    else:
        #x = x - li[k]
        k += 1
if x == li[k] or li[k] == 0:
    j += 1
print(str(j))

Submission status: Wrong Answer

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

if x<a[0]:
    print(0)
    quit()
for i in range(N):
    if c < x:
        c +=a[i]
        b +=1
    else:
        break

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

print(b)

Submission status: Wrong Answer

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

count = 0

a = sorted(a)

b = []

t = 0

for y in a:
  t += y
  if t>N:
    break
  else:
    b.append(y)
    
print(len(b))

Submission status: Wrong Answer

Solution code:
#入力
#3 70
#20 30 10

N,x=map(int,input().split())
a = [int(i) for i in input().split()]
a.sort()
#print(a)
happy=0
for i in range(N):
    if x>=a[i]:#菓子の数が欲しがる数が最小よりすくないなら終了
        x = x-a[i]#必要数が少ない人からあげてく，菓子の残数が減る
        happy=happy+1
        if x<=0:#菓子がなくなれば終わり
            break
    else:
        break
if x != 0:
    happy = happy-1
print(max(happy,0))

Submission status: Wrong Answer

Solution code:
# n, X = map(int, input().split())
# A = [int(x) for x in input().split()]
# A = sorted(A)

# def solve(a, x):
#     cnt = 0
#     for i in range(n):
#         for j in range(i,n):
#             if x >= a[j]:
#                 x -= a[j]
#                 cnt += 1
#     return cnt
    

# print(solve(A[::-1], X))


n, X = map(int, input().split())
A = [int(x) for x in input().split()]

A = sorted(A)

def solve(a, x, j):
    cnt = 0
    for i in range(j, n):
        if x >= a[i]:
            x -= a[i]
            cnt += 1
    if x == 0:
        return cnt
    else:
        return cnt - 1
    
res = 0
for i in range(n):
    res = max(res, solve(A, X, i))
    res = max(res, solve(A[::-1], X, i))
print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a = input().split()
a = [int(i) for i in a]
b = input().split()
b = [int(i) for i in b]
b = sorted(b)
output = 0
for i in range(len(b) - 1):
    if a[1] - b[i] > 0:
        a[1] += -b[i]
        output += 1
        if a[1] - b[-1] > 0:
            pass
        elif a[1] - b[-1] < 0:
            output -= 1
        else:
            output += 1
    elif(a[1] - b[i] == 0):
        output += 1
        break
    else:
        output -= 1
        break

print(output)

Submission status: Wrong Answer

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

A = sorted(A)

def solve(a, x, j):
    cnt = 0
    for i in range(j, n):
        if x >= a[i]:
            x -= a[i]
            cnt += 1
    if x == 0:
        return cnt
    else:
        return cnt - 1
    
res = 0
for i in range(n):
    res = max(res, solve(A[::-1], X, i))
print(res)

Submission status: Wrong Answer

Solution code:
def solver(N, x, requests):
    count = 0
    list.sort(requests)
    for req in requests:
        if x < req:
            break
        x -= req
        count += 1
    if count > 0 and x > 0:
        count -= 1
    return count
N, x = tuple([int(n) for n in input().split(" ")])
requests = [int(n) for n in input().split(" ")]
print(solver(N, x, requests))

Submission status: Wrong Answer

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

def f(a, x):
    print("f", a, x)
    if not a:
        return 0

    a.append(x)
    a = sorted(a)
    i = a.index(x)
    print("i", a, i)
    if i < len(a)-1:
        return len(a) - 2
    elif a[i-1] == a[i]:
        return len(a) - 2
    return f(a[:i-1], x-a[i-1])


s = sum(a)
if x == s:
    print(N)
elif x > s:
    print(N-1)
else:
    print(f(a, s-x))

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
from numpy import *
# import sys

N,x=map(int,input().split())
a=zeros(N)
a=[int(i) for i in input().split()]

a.sort()
count=0
for i in range(N):
    if(x-a[i]>=0):
        count+=1
        x-=a[i]
    else:
        break
print(count)

Submission status: Wrong Answer

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

if x<a[0]:
    print(0)
    quit()
for i in range(N):
    if c <= x:
        c +=a[i]
        b +=1
    else:
        break

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

print(b)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,x = map(int,input().split(' '))
a = list(map(int,input().split(' ')))

count = 0

a = np.array(sorted(a))

acum = a.cumsum()

for i,y in enumerate(acum):
  if y>=x:
    count = i
    break
    
print(min(count,N))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,x=map(int,input().split())
child = [int(i) for i in input().split()]
child.sort()
count=0
for i in child:
    if(x>=i):
        x-=i
        count+=1
    if(x<=0):
        break
if(x>0):
    if(count!=0):
        count-=1
print(count)

Submission status: Wrong Answer

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

al.sort()

used = 0
ans = 0
for a in al:
    if used+a > x:
        break
    used += a
    ans += 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
from numpy import *
import sys

N,x=map(int,input().split())
a=zeros(N)
a=[int(i) for i in input().split()]

a.sort()
i=0
count=0
for i in range(N):
    if(x-a[i]>=0):
        count+=1
        x-=a[i]
    else:
        break
print(count)

Submission status: Wrong Answer

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

al.sort()

used = 0
ans = 0
for a in al:
    if used+a > x:
        break
    used += a
    ans += 1

if used < 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()
b = 0
c = 0

if x<a[0]:
    print(0)
    quit()

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

for i in range(N):
    if c <= x:
        c +=a[i]
        b +=1
    else:
        break
print(b)

Submission status: Wrong Answer

Solution code:
from numpy import *
import sys
#

N,x=map(int,input().split())
a=zeros(N)
a=[int(i) for i in input().split()]

a.sort()
i=0
count=0
for i in range(N):
    if(x-a[i]>=0):
        count+=1
        x-=a[i]
print(count)

Submission status: Wrong Answer

Solution code:
def main():
    N,x=[int(i) for i in input().split()]
    a=input().split()
    k=0
    while True:
        if x>=int(min(a)):
            x=x-int(min(a))
            a.remove(min(a))
            k+=1
            if len(a)==0:
                break
        else:
            break
    print(k)
main()

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
a = sorted(map(int, input().split()))
if sum(a) == x:
    print(n)
    exit()
elif sum(a) < x:
    print(n - 1)
    exit()

y = x
ans = 0
for ai in a:
    if y - ai >= 0:
        y -= ai
        ans += 1
if y:
    b = a[:ans]
    sb = sum(b)
    for bi in b:
        for ai in a[ans:]:
            if sb - bi + ai == x:
                print(ans)
                exit()
    print(max(0, ans - 1))
else:
    print(ans)

Submission status: Wrong Answer

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

sum = 0;
ch = 0

for i in range(n):
    if sum == x:
        break
    
    sum += a[i]
    
    if sum  <= x:
        ch += 1

if sum != x:
    if ch:
        ch -= 1

print(ch)

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

Submission status: Wrong Answer

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

count = 0

a = sorted(a)

for y in a:
  if x>=y:
    count += 1
    x -= y
    
print(min(count,N))

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a=list(map(int, input().split()))
a.sort()
b = 0
c = 0
if sum(a)<x:
    b -= 1
if x<a[0]:
    print(0)
    quit()

for i in range(N):
    if c < x:
        c +=a[i]
        b +=1
    else:
        break
print(b)

Submission status: Wrong Answer

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

count = 0

a = sorted(a)

for y in a:
  if x>=y:
    count += 1
    x -= y
    
print(max(count,N))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a=list(map(int, input().split()))
a.sort()
b = 0
c = 0
if sum(a)<x:
    b -= 1
if x<a[0]:
    print(b)
    quit()

for i in range(N):
    if c < x:
        c +=a[i]
        b +=1
    else:
        break
print(b)

Submission status: Wrong Answer

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

al.sort()

used = 0
ans = 0
for a in al:
    if used+a > x:
        break
    used += a
    ans += 1

print(ans)

Submission status: Wrong Answer

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

count = 0

a = sorted(a)

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

Submission status: Wrong Answer

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

li = 0
li = list(map(int,input().split()))



j = 0
k = 0
while k < N - 1:
    if x > li[k]:
        j += 1
        x = x - li[k]
        k += 1
    else:
        #x = x - li[k]
        k += 1
if x == li[k]:
    j += 1
print(str(j))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
ame=list(map(int,input().split()))
ame=sorted(ame)
answer=0
for i in range(n):
    if m>=ame[i]:
        m=m-ame[i]
        answer=answer+1
    else:
        break
if  i==n-1 and m!=0:
    answer=answer-1
print(answer)

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans = 0
judge = [False for i in range(N)]
# print(judge)
for i in range(N):
    if x-a[i]>=0:
        judge[i]=True
        x-=a[i]
temp_count=0
for i in range(N):
    if judge[i]:
        temp_count+=1
# print(judge)
if sum(a)<x:
    print(temp_count-1)
else:
    print(temp_count)

Submission status: Wrong Answer

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

A = sorted(A)

def solve(a, x):
    cnt = 0
    if x < a[0]:
        return 0
    for i in range(n):
        if x >= a[i]:
            x -= a[i]
            cnt += 1
    if x == 0:
        return cnt
    else:
        return cnt - 1
    

print(max(solve(A, X), solve(A[::-1], X)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
a = sorted(a)
for i in range(len(a)):
	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()))
a.sort()
b = 0
c = 0
if sum(a)<x:
    b -= 1

for i in range(N):
    if c <= x:
        c +=a[i]
        b +=1
    else:
        break
print(b)

Submission status: Wrong Answer

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

al.sort()

used = 0
ans = N
for i, a in enumerate(al):
    if used+a > x:
        ans = i
        break
    used += a

print(ans)

Submission status: Wrong Answer

Solution code:
input_lines = input().split()
N = int(input_lines[0])
x = int(input_lines[1])
input_lines = input().split()
list_a = []
for i in range(N):
    list_a.append(int(input_lines[i]))

max = 0
for i in range(N):
    current_candy = x
    current_child = 0
    for j in range(i,N):
        tmp = current_candy - list_a[j]
        if tmp >= 0:
            current_candy = tmp
            current_child += 1
    if tmp > 0:
        current_child -= 1
    if current_child >= max:
        max = current_child

print(max)

Submission status: Wrong Answer

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

a = sorted(a, reverse=True)

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

print(solve(x))

Submission status: Wrong Answer

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

def func():
    cummulative_sum = 0
    for index, value in enumerate(A):
        cummulative_sum += value
        if cummulative_sum > x:
            index

    if cummulative_sum != x:
        return len(A) - 1
    else:
        return len(A)

ans = func()

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N,x = input().split()
N = int(N)
x = int(x)

a = input().split()

a = sorted(a)

xnum = 0
total = 0
i = 0
while (i<N):
    total = total + int(a[i])
    if (total <= x):
        xnum = xnum + 1
    i = i + 1

if (total < x):
    xnum = xnum - 1
print(xnum)

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans = 0
judge = [False for i in range(N)]
# print(judge)
for i in range(N):
    if x-a[i]>=0:
        judge[i]=True

temp_count=0
for i in range(N):
    if judge[i]:
        temp_count+=1
if sum(a)<x:
    print(temp_count-1)
else:
    print(temp_count)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
ame=list(map(int,input().split()))
ame=sorted(ame)
answer=0
for i in range(n):
    if m>ame[i]:
        m=m-ame[i]
        answer=answer+1
    else:
        break
if i==n-1 and m!=0:
    answer=answer-1
print(answer)

Submission status: Wrong Answer

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

sum = 0;
ch = 0
for i in range(n):
    sum += a[i]
    if sum > x:
        break;
    else:
        ch += 1
    if sum == x:
        break

if sum != x and ch != 0:
    ch -= 1
    
print(ch)

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

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

Submission status: Wrong Answer

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

    if (x == 0):
        print(0)
        return
    candy = 0
    for i in range(n):
        candy += an[i]
        if (candy > x):
            print(i)
            return

    print(n)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans = 0
tmp = []

for i in range(0, N):
    tmp = min(a)
    if x >= min(a):
        x -= tmp
        a.remove(tmp)
        ans += 1
    else :
        break

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

print(ans)

Submission status: Wrong Answer

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

    if (x == 0):
        print(0)
    candy = 0
    for i in range(n):
        candy += an[i]
        if (candy > x):
            print(i)
            return

    print(n)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

count = 0
minusPoint = 0
for i in range(n):
    if x - a[i] >= 0:
        count += 1
        x -= a[i]
if x == 0:
    print(count)
    exit()
elif count > 0:
    count -= 1
    x += a[count]
    for j in range(count, n):
        if x == a[j]:
            count += 1
            break
print(count)

Submission status: Wrong Answer

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

a.sort(reverse=True)

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

Submission status: Wrong Answer

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

arr.sort()
cnt = 0
for ele in arr:
    if x < ele:
        if x != 0:
            cnt -= 1
        break
    x -= ele
    cnt += 1

print(cnt)

Submission status: Wrong Answer

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

s = list(map(int,input().split()))
s.sort()
print(s)
count = 0
for i in range(N):
	if k - s[i] >= 0:
		count += 1
		k -= s[i]
	else:
		break

if count == N :
	if k>0:
		count -= 1
	print(count)
else:
	print(count)

Submission status: Wrong Answer

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

    if (x == 0):
        print(0)
    candy = 0
    for i in range(n):
        candy += an[i]
        if (candy > x):
            print(i)
            return

    print(n+1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

count = 0

a = sorted(a)

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

Submission status: Wrong Answer

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

a = sorted(a)

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

print(solve(x))

Submission status: Wrong Answer

Solution code:
N, M = map(int, raw_input().split())
a = map(int, raw_input().split())

sorted(a)

sum = 0
itr = 0
for i in range(N):
  sum = sum+a[i]
  if sum >= M:
    itr = i
    break
    
if sum < M:
  print N-1
elif sum == M:
  print itr+1
elif sum > M:
  print itr

Submission status: Wrong Answer

Solution code:
import sys

n, x = map(int, input().split())
A = list(map(int, input().split()))
#print(A)

B = sorted(A)
s = sum(A)

if x > s:
    #i = A.index(B[0])
    #print(' '.join(map(str, A[0:i])) + ' ' + str(x-s+B[0]) + ' ' + ' '.join(map(str, A[i+1:n])))
    print(n-1)
    sys.exit(0)
elif x == s:
    #print(' '.join(A))
    print(n)
    sys.exit(0)

for i in range(n-1,0,-1):
    #print(B[0:n-i])
    v = s - sum(B[0:n-i])
    if v <= x: break

if i == 1:
    if B[0] == x:
        print(1)
    else:
        print(0)
    sys.exit(0)

print(i)

Submission status: Wrong Answer

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

    if (x == 0):
        print(0)
    candy = 0
    for n in range(n):
        candy += an[n]
        if (candy > x):
            print(n)
            return

    print(n+1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

sum = 0;
ch = 0
for i in range(n):
    sum += a[i]
    if sum > x:
        break;
    else:
        ch += 1
        
if sum != x:
    ch -= 1
    
print(ch)

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

Submission status: Wrong Answer

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

arr.sort()
cnt = 0
for ele in arr:
    if x < ele:
        break
    x -= ele
    cnt += 1

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

count = 0

a.sort()

for y in a:
  x -= y
  if x>=0:
    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()]
    num = 0
    for i in sorted(a):
        x -= i
        if x >= 0:
            num += 1
        else:
            break

    print(num)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
n, x = list(map(int, input().split()))
array = list(map(int, input().strip().split()))
array.sort()
ans = 0
for i in array:
    x = x-i
    if x < 0:
        break
    ans += 1
    
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

n, x = map(int, input().split())
A = list(map(int, input().split()))
#print(A)

B = sorted(A)
s = sum(A)

if x > s:
    #i = A.index(B[0])
    #print(' '.join(map(str, A[0:i])) + ' ' + str(x-s+B[0]) + ' ' + ' '.join(map(str, A[i+1:n])))
    print(n-1)
    sys.exit(0)
elif x == s:
    #print(' '.join(A))
    print(n)
    sys.exit(0)

for i in range(n-1,0,-1):
    #print(B[0:n-i+1])
    v = s - sum(B[0:n-i+1])
    if v <= x: break

if i == 1:
    if B[0] == x:
        print(1)
    else:
        print(0)
    sys.exit(0)

print(i)

Submission status: Wrong Answer

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

s = list(map(int,input().split()))
s.sort()

count = 0
for i in range(N):
	if k - s[i] >= 0:
		count += 1
		k -= s[i]
	else:
		break

if k>0:
	count -= 1
print(count)

Submission status: Wrong Answer

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

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

print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    candy = 0
    for n in range(n):
        candy += an[n]
        if (candy > x):
            print(n)
            return

    print(n+1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

a.sort()

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