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

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

Submission status: Wrong Answer

Solution code:
import numpy as np
list = input().split(" ")
x = int(list[1])
a = input().split(" ")
a_num = np.array([int(n) for n in a])

a = np.sort(a_num)

for i in range(len(a)):
  if x < a[i]:
    print(str(i))
    break
  x -= a[i]
print(len(a))

Submission status: Wrong Answer

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

a.sort()
print(a)

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

Submission status: Wrong Answer

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

ans = 0
for i in a:
  x -= i
  if x < 0:
    break
  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)

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

    print(n)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

happy=0
a.sort()

for i in range(N):
    
    if a[i] > x:
        break

    else:
        x=x-a[i]
        happy=happy+1

if x!=0 and happy>0:
    happy=happy-1
    
print(happy)

Submission status: Wrong Answer

Solution code:
NX = input()
NX = NX.split(' ')
N = int(NX[0])
x = int(NX[1])
A = input()
A = list(map(int, A.split(' ')))
sorted_a = sorted(A)
s = 0

cum_sum = [0] * (len(sorted_a))
for i, a in enumerate(sorted_a):
    s = s + a
    cum_sum[i] = s

for i, s in enumerate(cum_sum):
    if s > x:
        print(i)
        break

if i == len(cum_sum)-1 and s == x:
    print(i+1)

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

Submission status: Wrong Answer

Solution code:
nx = input().split()
an = input().split()

n = int(nx[0])
x = int(nx[1])

count = 0

for i in range(len(an)):
    if (x >= int(an[i])):
        x = x - int(an[i])
        count += 1

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

Submission status: Wrong Answer

Solution code:
xy=input().split()
n=int(xy[0])
x=int(xy[1])
l=input().split()
l.sort()
sum=0
i=0
while sum<=x and i+1<=n:
    sum=sum+int(l[i])
    i=i+1
    print(sum)
if sum<x:
    print(i-1)
else:
    print(i)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
a = sorted(a, reverse = True)
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 = list(map(int,input().split()))
a_list_sort = sorted(a_list)
#print(a_list)
#print(a_list_sort)
count = 0

if sum(a_list) <= x :
	count = N
else:
	for i in range(N):
		if sum(a_list_sort[:i+1]) <= x:
			continue	
		else:
			count = i
			break
print(count)

Submission status: Wrong Answer

Solution code:
import itertools
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.append(0)
comb=list(itertools.combinations_with_replacement(a,n))
ans=[]
for i in comb:
    per=sum(i)
    if per==x:
        if 0 in i:
            ans.append(len(set(i))-1)
        else:
            ans.append(len(set(i)))
    if n in ans:
        print(ans[-1:])
if len(ans)==0:
    print(0)
else:
    print(max(ans))

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
res = int()
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())
A = sorted([int(x) for x in input().split()])

count = 0

for a in A:
    if X - a < 0:
        break
    else:
        X -= a

    count += 1

if X > 0 and count > 1:
    count -= 1

print(count)

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.append(min(a))
    a.remove(tmp[i])

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

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

print(ans)

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 = len(a_sum)
for i in range(len(a_sum)):
    if a_sum[i] > x:
        ans = i
        break

print(ans)

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
    f = False
    for i in range(n):
        if x >= a[i]:
            x -= a[i]
            cnt += 1
            f = True
        else:
            break
        if x == 0:
            return cnt
    if f:
        return cnt - 1
    else:
        return cnt

print(solve(x))

Submission status: Wrong Answer

Solution code:
NX = input()
NX = NX.split(' ')
N = int(NX[0])
x = int(NX[1])
A = input()
A = list(map(int, A.split(' ')))
sorted_a = sorted(A)
s = 0

cum_sum = [0] * (len(sorted_a))
for i, a in enumerate(sorted_a):
    s = s + a
    cum_sum[i] = s

for i, s in enumerate(cum_sum):
    if s > x:
        print(i)
        break

if i == len(cum_sum)-1:
    print(i+1)

Submission status: Wrong Answer

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

childlen = []
for part in input().split():
    childlen.append(int(part))

childlen.sort()
#print(childlen)

happy = 0
for n in range(len(childlen)):
    #print(child, x)
    child = childlen[n]

    if child <= x:
        x -= child
        happy += 1
    else:
        break

if x != 0:
    happy -= 1

print(happy)

Submission status: Wrong Answer

Solution code:
import numpy as np

N, x = list(map(int, input().split()))
a = np.asarray(list(map(int, input().split())))
a = np.sort(a)
s = 0
for i in range(1, N):
    if np.sum(a[:i]) < x:
        s += 1
if np.sum(a) == x:
    s += 1
print(s)

Submission status: Wrong Answer

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

an.sort()

# print(an)
ans = 0

for ai in an:
    if x >= ai:
        x -= ai
        ans += 1
    else:
        break


if x > 0:
    if ans > 0:
        if ans == len(an):
            pass
        else:
            ans -=1
    else:
        ans = 0

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

N, x = sys.stdin.readline().split()
N = int(N)
x = int(x)
al = [int(a) for a in sys.stdin.readline().split()]

al.sort()

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

print(ans)

Submission status: Wrong Answer

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

happy=0
a.sort()

for i in range(N):
    
    if a[i] > x:
        break

    else:
        x=x-a[i]
        happy=happy+1

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

Submission status: Wrong Answer

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

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 = len(a_sum)
for i in range(len(a_sum)):
    if a_sum[i] > x:
        ans = i - 1


print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
list = input().split(" ")
x = int(list[1])
a = input().split(" ")
a_num = np.array([int(n) for n in a])

a = np.sort(a_num)

for i in range(len(a)):
  if x < a[i]:
    print(str(i))
  x -= a[i]

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

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
for ax in a:
    total = total + int(ax)
    if (total <= x):
        xnum = xnum + 1

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

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

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:
	if count == 0:
		print(0)
	else:
		print(count-1)
else:
	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 score in a:
    if x // score > 0:
        num =  a.count(score)
        if num > 1:
            dist_num = x // score
            if dist_num < num:
                cnt += dist_num
            else:
                cnt += num
        else:
            cnt += 1
        x = x % score
print(cnt)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

n, x = map(int, input().split())
sa = input().split()
a = []

for s in sa:
    a.append(int(s))

a = sorted(a)

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

if sum != x 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()))
answer = []
for i in range(n):
    if i == n-1:
        if x == a[i]:
            answer.append(1)
        else:
            answer.append(0)
    else:
        if x >= a[i]:
            answer.append(1)
            x -= a[i]
        else:
            answer.append(0)
print(sum(answer))

Submission status: Wrong Answer

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

happy=0
a.sort()

for i in range(N):
    
    if a[i] > x:
        break

    else:
        x=x-a[i]
        happy=happy+1

print(happy)

Submission status: Wrong Answer

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

b.sort()
b.reverse()

snu = a[1]

c = 0
for i in b:
    if i <= snu:
        snu-=i
        c+=1

if snu!=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()))
ans = 0
a.sort()

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

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

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]
	if 0 > k:
		break

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

Submission status: Wrong Answer

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

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

print(cnt)

Submission status: Wrong Answer

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

a.sort()

score = 0
count = N
for i in range(N):
    score+=a[i]
    if score > x:
        count = i
        break

if count==N:
    count-=1

print count

Submission status: Wrong Answer

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

n, x = map(int, input().split())
sa = input().split()
a = []

for s in sa:
    a.append(int(s))

a = sorted(a)

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

print(ans)

Submission status: Wrong Answer

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

children = sorted(children)
for i in children:
  if x < i:
    break
  elif x == i:
    ans += 1
    break
  elif i == max(children):
    break
  else:
    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()

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

Submission status: Wrong Answer

Solution code:
iN,iX = [int(x) for x in input().split()]
aL = [int(x) for x in input().split()]
aL.sort()
iCounter = 0
for iE in aL:
    if iX >= iE:
        iX -= iE
        iCounter += 1
    else:
        break
#余ってる
if iX > 0 and iCounter > 0:
    iCounter -= 1
print(iCounter)

Submission status: Wrong Answer

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

an.sort()

# print(an)
ans = 0
for ai in an:
    if x >= ai:
        x -= ai
        ans += 1
    else:
        break

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

print(ans)

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

print(cnt)

Submission status: Wrong Answer

Solution code:
# encoding: utf-8
# N = int(input())
# S = input()
# N, M = map(int, input().split())
# A = list(map(int, input().split()))

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

ans = 0
x_tmp = x

for Ai in sorted(A):
    x_tmp -= Ai
    if x_tmp > 0: ans += 1
    elif x_tmp == 0:
        ans += 1
        break
    else:
        if ans > 0: ans -= 1
        break

if x_tmp > 0: ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

# なんこか入力
n,x = map(int, input().split())

# 空白区切りの数列をリストに代入
a = [int(i) for i in input().split()]

a=sorted(a)

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

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]
	if 0 > k:
		break
if k > 0:
	print(count-1)
else:
	print(count)

Submission status: Wrong Answer

Solution code:

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

childlen = []
for part in input().split():
    childlen.append(int(part))

childlen.sort()
#print(childlen)

happy = 0
for child in childlen:
    #print(child, x)
    if child <= x:
        x -= child
        happy += 1
    else:
        break

print(happy)

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)
res=0
for num in a:
    if num<=x:
        x-=num
        res+=1
    else:
        break
if x != 0 and res>0:
    res-=1
print(res)

Submission status: Wrong Answer

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

b.sort()

snu = a[1]

c = 0
for i in b:
    if i <= snu:
        snu-=i
        c+=1

if snu!=0 and c!=0:
    c-=1

print(c)

Submission status: Wrong Answer

Solution code:
N, x = list(map(int, input().split()))
ais = list(map(int, input().split()))
s = 0
cnt = 0
ais.sort()
for ai in ais:
    if(s+ai>=x):
        break
    else:
        s += ai
        cnt += 1
print(cnt)

Submission status: Wrong Answer

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

for i in range(n):

	if x < arr[i]:
		break;
	else:
		ans+=1;
		x -= arr[i];

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

print(ans);

Submission status: Wrong Answer

Solution code:
N, x = map(int,input().split())
listA = [int(i) for i in input().split()]
listA.sort()
cnt = 0
X = x
for j in listA:
    if X - j < 0:
        break
    else:
        X = X - j
        cnt += 1

if X != 0 and cnt != 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 ai in a:
	if x <= 0:
		break
	if x >= ai:
		x -= ai
		count += 1

print(count)

Submission status: Wrong Answer

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

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()))
    svalues = sorted(values)
    res = 0
    for i in svalues:
        if i <= x:
            x -= i
            res += 1
        else:
            break
    if x != 0:
        res -= 1
    print(res) if res != -1 else print(0)


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()]
b = [0 for i in range(n)]
a = sorted(a)

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

Submission status: Wrong Answer

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

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

c_list.sort()


i = 0
for _ in range(len(c_list)):
    if x - c_list[i] < 0:
        print(i)
        exit()
    x -= c_list[i]
    i += 1

print(len(c_list))

Submission status: Wrong Answer

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

A.sort()
ans = 0
for a in A:
    if a <= x:
        ans += 1
        x -= a
if x != 0 and ans != 0:
    ans -= 1
print(ans)

Submission status: Wrong Answer

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

lis = map(int, input().split())


count = 0
for i in sorted(lis):
    x -= i
    if x < 0:
        break
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import sys

N, x = sys.stdin.readline().split()
N = int(N)
x = int(x)
al = [int(a) for a in sys.stdin.readline().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:
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))

count = 0

for i in range(N):
    if a[i] <= x and i != (N-1):
        count += 1
        x -= a[i]
    elif a[i] == x and i == (N-1):
        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)
cnt = 0
for i in range(n):
    if x >= a[i]:
        x -= a[i]
        if x > 0:
            cnt += 1
        elif x == 0:
            cnt += 1
            break

if x != 0:
    cnt -= 1

print(max(cnt, 0))

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
A = list(map(int,input().split()))
answer = 0
while x > 0  :
    A = sorted(A)
    if x < A[0] :
        break
    x = x - A[-1]
    answer += 1
    A.pop(-1)
    if len(A) == 0 :
        if x != 0 :
            answer -= 1
        break
print(answer)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, x = list(map(int, input().split()))
ais = list(map(int, input().split()))
s = 0
cnt = 0
ais.sort()
for ai in ais:
    if(s+ai>x):
        break
    else:
        s += ai
        cnt += 1
print(cnt)

Submission status: Wrong Answer

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

A.sort()

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

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

print(max(0, ans - (x != 0)))

Submission status: Wrong Answer

Solution code:
def main():
    n, x = [int(s) for s in input().split()]
    a = [int(s) for s in input().split()]
    a.sort()
    m = 0

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

    if x != 0:
        m = max(0, m - 1)
    print(m)

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 :
      print(i)
      break
else :
   print(n)

Submission status: Wrong Answer

Solution code:
n, x = map(int, raw_input().split())
a = map(int, raw_input().split())
a.sort()
for i, t in enumerate(a):
    x -= t
    if x < 0:
        print i
        break
else:
    print n - 1 if t else n

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

if x != 0:
    cnt -= 1

print(max(cnt, 0))

Submission status: Wrong Answer

Solution code:


N,x = [int(x) for x in input().split()]

al = [int(x) for x in input().split()]


al.sort()

count=0
acc = 0
for ai in al:
    acc += ai
    if acc > x:
        break
    count+=1

print(count)

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]
	if 0 > k:
		break 
print(count)

Submission status: Wrong Answer

Solution code:
n, x = map(int, raw_input().split())
a = map(int, raw_input().split())
a.sort()
for i, t in enumerate(a):
    x -= t
    if x < 0:
        print i
        break
else:
    print n

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 score in a:
    if x // score > 0:
        x = x % score
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
N,x = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
i = 0
tmp =0
while True:
    if i == len(A):
        print(i)
        exit()
    else:
        tmp += A[i]
        if tmp > x or i == len(A):
            print(i)
            exit()
        else:
            i += 1

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:
        x -= a
        ans += 1

print(ans - (x != 0))

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:
        x -= ai
        ans += 1
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
A = list(map(int,input().split()))
answer = 0
while x > 0  :
    A = sorted(A)
    if x < A[0] :
        break
    x = x - A[-1]
    answer += 1
    A.pop(-1)
    if len(A) == 0 :
        break
print(answer)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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]
print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

in_strings = lambda: stdin.readline()[:-1] # s = in_strings()
in_int = lambda: int(stdin.readline()) # N = in_int()
in_intlist = lambda: list(map(int, stdin.readline().split())) # List = in_intlist()

N, X = in_intlist()
a_list = in_intlist()

a_list.sort()
print(a_list)

flag = 1
dist = 0
count = 0
for i in range(N):
    dist += a_list[i]
    if dist <= X:
        count += 1
    else:
        flag = 0
        break
if flag and (dist < X):
    count -= 1

print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n,x = map(int, input().split())
a = sorted([int(x) for x in input().split()])

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

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

print(i)

Submission status: Wrong Answer

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

A.sort()

ans = 0
for a in A:
    if a <= x:
        ans += 1
        x -= a
    else:
        break

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:

def main():
    n, x = map(int,input().split())
    a = list(map(int,input().split()))

    a = sorted(a)
    ans = 0
    tmp = 0
    for i in a:
        tmp += i
        if tmp <= x:
            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()))
ans = 0
Sums = 0
A.sort()
for i in range(N-1):
    Sums += A[i]
    if A[i] > x:
        break
    ans += 1
Sums += A[N-1]
if Sums == x:
    ans += 1
print(ans)