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: Accepted

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))
answer = bisect_right(Acum,X)
if answer == N:
    if Acum[-1] < X:
        answer -= 1
print(answer)

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N, x = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
cnt = 0
for a in A:
    if x >= a:
        cnt += 1
        x -= a
    else:
        x = 0
if x > 0:
    cnt -= 1
print(cnt)

Submission status: Accepted

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

ans = 0
total = 0

a_list.sort()

for i, a in enumerate(a_list):
    total += a

    if x < total:
        break
            
    elif i == len(a_list) - 1 and x > total:
        None
        
    else:
        ans += 1
    
print(ans)

Submission status: Accepted

Solution code:
N,x=map(int,input().split())
A=list(map(int,input().split()))
A_1=sorted(A)
num=0
total=0
if A_1[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:
            break
        else:
            num+=1

else:
    num=N-1
print(num)

Submission status: Accepted

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 + 1)
        break
    elif cou > x:
        print(i)
        break
else:        
    print(n-1)

Submission status: Accepted

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 and x-A[0] > 0:
    print(N-1)
    break
  elif i == N-1 and x-A[0] == 0:
    print(N)
    break
  else:
    x -= min(A)
    A.remove(min(A))
    cnt += 1

Submission status: Accepted

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()
if cou == x:
    print(n)
else:
    print(n-1)

Submission status: Accepted

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:
        x = 0
        break

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

print(cnt)

Submission status: Accepted

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
    if X < 0:
        print(j-1)
    else:
        print(j)

Submission status: Accepted

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

Submission status: Accepted

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

for i, a in enumerate(A):
    if a > x:
        print(answer)
        exit()
    if i == N-1:
        if a != x:
            print(answer)
        else:
            answer += 1
            print(answer)
    else:
        x -= a
        answer += 1

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

r = 0
for a in A:
    if x - a < 0:
        break
    else:
        x -= a
        r += 1
if x > 0 and r == N:
    r -= 1

print(r)

Submission status: Accepted

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

Submission status: Accepted

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: Accepted

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

arr.sort()
ans = 0

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

if arr[-1] == x:
    ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

A = sorted(a)

for i in range(N):
    maxcandy += A[i]

for i in range(N):
    if x >= A[i]:
        x = x - A[i]
        count += 1
    else:
        break

if maxcandy < X:
    print(count-1)
else:
    print(count)

Submission status: Accepted

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

Submission status: Accepted

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
    ans+=1
print(ans-(x>0))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, x = map(int, input().split())
    A = sorted(list(map(int, input().split())))

    res = 0
    for i in range(n):
        if i == n - 1 and A[i] < x:
            continue

        if A[i] <= x:
            x -= A[i]
            res += 1

    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

def readlines(n):
    for _ in range(n):
        yield map(int, input().split())


def main():
    N, x = map(int, input().split())
    A = sorted(map(int, input().split()))

    for a in A:
        if a > x:
            yield 0
            return
        elif x > 0:
            x -= a
            yield 1
        else:
            yield 0
            return

    if x > 0:
        yield -1

print(sum(main()))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

a.sort()
c = 0
ans = 0

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

if c == x:
    print(N)
else:
    print(N-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,X=map(int,input().split())
A=[int(i) for i in input().split()]
A.sort()
cnt=0
if sum(A)<X: cnt-=1
for i,a in enumerate(A):
    X-=a
    if X>=0:
        cnt+=1
    else:
        break
print(cnt)

Submission status: Accepted

Solution code:
from sys import stdin
import math

[N, x] = list(map(int, stdin.readline().rstrip().split()))
a = list(map(int, stdin.readline().rstrip().split()))

a_sorted = sorted(a)


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

if x > 0:
    count -= 1

print(count)

Submission status: Accepted

Solution code:
_, x, *a = map(int, open(0).read().split())
c = 0
for i in sorted(a):
  x -= i
  if x<0:
    break
  c += 1
print(c - (x>0))

Submission status: Accepted

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

for i in range(1, len(A)+1):
    #print(i)
    #print(A[:i])
    #print(sum(A[:i]))
    if x < sum(A[:i]):
        #print('a')
        print(i-1)
        break
    elif x == sum(A[:i]):
        #print('b')
        print(i)
        break
    else:
        if i == len(A):
            print(i-1)

Submission status: Accepted

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

count = 0
for i in range(len(A)):
    if (x >= 0):
        x = x - A[i]
        count += 1
    else:
        break

if (x > 0):
    print(count - 1)
elif(x == 0):
    print(count)
elif(x < 0):
    print(count - 1)

Submission status: Accepted

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


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    n, x = map(int, input().split())
    aaa = list(map(int, input().split()))
    aaa.sort()
    ans = 0
    for a in aaa:
        if x < a:
            break
        ans += 1
        x -= a
    else:
        if x > 0:
            ans -= 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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
if sum(num_list) < X:
    print(index-1)
else:
    print(index)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    if sum(a[:ans]) == x:
        print(ans)
    else:
        print(ans-1)

Submission status: Accepted

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 sum(a[:i + 1]) <= x:
        ans = i+1
    else:
        print(i)
        exit()

if sum(a[:ans]) == x:
    print(ans)
else:
    print(ans-1)

Submission status: Accepted

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

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


print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,X=map(int,input().split())
L=list(map(int,input().split()))
L=sorted(L)
count=0
for i in range(N):
	if i==(N-1):
		if X!=L[i]:
			count=count
		else:
			count+=1
	elif L[i]<=X:
		X-=L[i]
		count+=1
	
print(count)

Submission status: Accepted

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

# A - Candy Distribution Again
N, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
candies = 0
ans = 0

for ai in a:
	if candies < x:
		candies += ai
		ans += 1
	else:
		break

if candies != x:
	ans -= 1

print(ans)

Submission status: Accepted

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]:
    if i == N-1:
      l[i] = X
      X -= X
    else:
      l[i] = A[i]
      X -= A[i]
  else:
    l[i] = X
    X -= X
ans = [A[i]-l[i] for i in range(N)].count(0)
print(ans)

Submission status: Accepted

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]
  else:
    break
if x == 0 or cnt < n:
  print(cnt)
else:
  print(cnt-1)

Submission status: Accepted

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

Submission status: Accepted

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]
  else:
    break

if x == 0 or ans < N:
  print(ans)
else:
  print(ans-1)

Submission status: Accepted

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]
  else:
    break

if x == 0 or ans == 0 or ans < N:
  print(ans)
else:
  print(ans-1)

Submission status: Accepted

Solution code:
import numpy as np
n,x = map(int,input().split())
li = list(map(int,input().split()))
li.sort()
res = np.cumsum(li)
cnt=0
if res[-1] == x:
    cnt = len(res)
elif res[-1] > x:
    for i in res:
        if i <= x:
            cnt += 1
        else:
            break
else:
    cnt = len(res) -1
print(cnt)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

if x > sum(a):
    print(N-1)
    exit()

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

Submission status: Accepted

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: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

if x == sum(sweets):
    print(N)
else:
    # 少ないものから順に取っていく
    sweets.remove(max(sweets))
    ans = N - 1
    while True:
        if x >= sum(sweets):
            print(ans)
            break

        sweets.remove(max(sweets))
        ans -= 1

Submission status: Accepted

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

ans=0
if sum(a_inputs)<x:
    ans=n-1
else:
    while a_inputs:
        a = a_inputs.pop(0)
        if a<=x:
            x-=a
            ans+=1
        else:
            break
print(ans)

Submission status: Accepted

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

ans = 0
if x == sum(a):
    print(n)
    quit()
elif x > sum(a):
    print(n-1)
    quit()
else:
    for i in range(n):
        if x - a[i] < 0:
            break
        x -= a[i]
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def getInput():
    return [int(i) for i in input().rstrip().split(' ')]

N, x = getInput()
a = sorted(getInput())
cnt=0
for i in a:
    x -= i
    if x<0: break
    cnt+=1

print(cnt-(x>0))

Submission status: Accepted

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]
    if i == n-1 and x != 0:
      ans -= 1
  else:
    break
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if x > sum(a):
    ans -= 1
print(ans)

Submission status: Accepted

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
if ans == n and x > 0:
    print(ans-1)
else:
    print(ans)

Submission status: Accepted

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: Accepted

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 and cnt == n:
    cnt -= 1

print(cnt)

Submission status: Accepted

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:
        ans += 1
if x>=1:
    ans-=1
print(ans)

Submission status: Accepted

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):
    x -= A[i]
    if x < 0:
        break
    cnt += 1

if cnt==N and x > 0:
    cnt -= 1
print(cnt)

Submission status: Accepted

Solution code:
a,b = map(int, input().split())
arr = sorted(list(map(int, input().split())))
res = 0
tmp = 0
for i in range(a):
  tmp += arr[i]
  if tmp <= b:
    res = i+1
if res == a and tmp < b:
  res -= 1
print(res)

Submission status: Accepted

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

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

print(i)

Submission status: Accepted

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.sort()
ans = 0
flg = True
for i in range(N):
    if arrA[i]<=x:
        x -= arrA[i]
        ans += 1
    else:
        flg = False

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

Submission status: Accepted

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

a.sort()
ans = 0
frag = True
for i in range(n):
    if x >= a[i]:
        x -= a[i]
        ans += 1
    else:
        frag = False

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

Submission status: Accepted

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

Submission status: Accepted

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

a.sort()

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

if x > 0:
    ans -= 1

print(ans)

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
li = list(map(int,input().split()))
li.sort()
count = 0
for l in li:
    x -= l
    if x >= 0:
        count += 1
    else:
        break
if x > 0:
    count -= 1
    print(max(0,count))
else:
    print(count)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

a.sort()
if sum(a) == x:
    print(N)
else:
    i = 0
    candy = 0
    while candy <= x and i <= N - 1:
        candy += a[i]
        i += 1
    print(i - 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a.sort()
count = 0

for i in range(len(a)):
    tmp = a[i]

    if x >= tmp and i != len(a) - 1:
        count += 1
        x -= tmp
    else:
        if tmp == x:
            count += 1
        break

print(count)

Submission status: Accepted

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline

def main():
    N, X = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    ret = 0
    cnt = 0
    if sum(A)<X:
        print(N-1)
    elif sum(A)==X:
        print(N)
    else:
        for i in range(N):
            X-=A[i]
            if X<0:
                break
        print(i)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N, x = map(int, input().split())
    A = list(map(int, input().split()))
    cnt = 0
    heapify(A)
    while True:
        if cnt < N:
            p = heappop(A)
            x -= p
            if x>=0:
                cnt += 1
            else:
                break
        else:
            break
    if cnt==N and x!=0:
        cnt-=1
    print(cnt)


resolve()

Submission status: Accepted

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

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

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

Submission status: Accepted

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
if cnt == n:
    cnt-=1
print(cnt)

Submission status: Accepted

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

while ans < N:
    snack_sum += a[ans]
    if snack_sum > x:
        break
    else:
        ans += 1

if ans == N:
    if snack_sum != x:
        print(ans - 1)
        exit()
print(ans)