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:
# AGC 027 A - Candy Distribution Again
N, x = map(int,input().split())
an = list(map(int,input().split()))

ak =[] 
while len(an) > 0:
    ak.append(min(an))
    del an[an.index(min(an))]

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

    if x == 0:
        break
print(count)

Submission status: Accepted

Solution code:
import math


def resolve():
    import sys
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    # n = int(input().rstrip())
    import heapq  # heapqライブラリのimport
    nx = [int(x) for x in input().rstrip().split(" ")]
    x = nx[1]
    a_list = [int(x) for x in input().rstrip().split(" ")]

    heapq.heapify(a_list)
    ans = 0
    while len(a_list) > 0:
        a = heapq.heappop(a_list)

        if len(a_list) == 0:
            if(x == a):
                ans += 1
            break
        if x >= a:
            ans += 1
            x -= a
        else:
            break


    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

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

        else:
            if A[i] <= x:
                ans += 1
                x -= A[i]
    print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

print(max(res-1, 0) if x>0 else res)

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 A[i]<=X:
        X-=A[i]
        cnt+=1
    else:
        break
if X>0 and cnt==N:
    cnt-=1
print(cnt)

Submission status: Accepted

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

res = 0
if x == sum(a):
  res = N
elif x > sum(a):
  res = N -1
else:
  a.sort()
  while x > 0:
    if x >= a[0]: res += 1
    x -= a.pop(0)

print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, x = inintm()
A = inintl()

A.sort()
ans = 0

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

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

if a[N - 1] == x:
    ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
  N, x = map(int, input().split())
  A = list(map(int, input().split()))
  A.sort()
  ans = 0
  for i in range(N):
    if i==N-1:
      if A[i]==x:
        ans += 1
      continue
    if x>=A[i]:
      ans += 1
      x -= A[i]
  return ans
print(solve())

Submission status: Accepted

Solution code:
import sys
import collections
import bisect


def main():
    n, x = map(int, input().split())
    a = sorted(list(map(int, input().split())))
    k = 0
    ans = 0
    for i in range(n):
        k += a[i]
        if k > x:
            print(ans)
            return
        ans += 1
    print(ans if sum(a) == x else ans - 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import accumulate
N, X = [int(x) for x in input().split()]
a = sorted([int(x) for x in input().split()])
p = list(accumulate(a))

result = 0
for i, x in enumerate(p):
  if X < x:
    break
  if i == N-1 and x != X:
    break
  result += 1

print(result)

Submission status: Accepted

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

if x < min(A):
    print(0)
    exit()

A.sort()
ans = 0
i = 0
while x > 0 and ans < N:
    if x >= A[i]:
        x -= A[i]
        ans += 1
        i += 1
    else:
        x = 0
        break

if x > 0:
    ans -= 1

print(ans)

Submission status: Accepted

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

if sum(a) > x:
    while sum(a) > x:
        del a[-1]
    print(len(a))
else:
    print(N) if sum(a) == x else print(N-1)

Submission status: Accepted

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

a.sort()

res = 0

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

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


print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n,x = map(int,readline().split())
lst1 = list(map(int,readline().split()))

lst1.sort()

i = 0
ans = 0
while i < n:
    if lst1[i] > x:
        break
    x -= lst1[i]
    ans += 1
    i += 1

if i == n:
    if x == 0:
        print(ans)
    else:
        print(ans-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
from typing import SupportsComplex


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

result = []
for v in a:
    if x >= v:
        result.append(v)
        x -= v
    else:
        break

if len(result) == 0:
    print(0)
    exit()

if (x > 0) and (len(result) == len(a)):
    result[-1] += x

if result[-1] != a[len(result)-1]:
    ans = len(result)-1
else:
    ans = len(result)

print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
L = list(map(int,input().split()))
L.sort()

sum1 = 0
cnt = 0
if k < L[0]:
    print(0)
    exit()
for i in range(n):
    sum1 +=L[i]
    if sum1 <=k:
        cnt +=1
        if i == n-1 and sum1 != k:
            cnt -=1
    else:
        break
print(cnt)

Submission status: Accepted

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

count = 0

a.sort()

for idx, v in enumerate(a):
    if v <= x:
        x -= v
        if idx == N - 1:
            if x == 0:
                count += 1
        else:
            count +=1

print(count)

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

if sum(a)==x:
    print(n)
elif sum(a)<x:
    print(n-1)
else:
    total=0
    cnt=0
    for a_i in a:
        if total+a_i<=x:
            total+=a_i
            cnt+=1
        else:
            break
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
sum_a = sum(a)
cnt = 0
a.sort()
if x > sum_a:
    cnt = n - 1
elif x == sum_a:
    cnt = n
else:
    for i in a:
        if i <= x:
            x -= i
            cnt += 1
        else:
            break
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

aN.sort()
ans = 0
for n in range(N):
  if x >= aN[n]:
    ans += 1
    x -= aN[n]
  else:
    print(ans)
    sys.exit()
print(N if x == 0 else N-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
total=0
j=0
ssum=sum(a)

if ssum>=x:
    for i in range(N):
        total+=a[i]
        if total>x:
            break
        j+=1
    print(j)
else:
    print(N-1)

Submission status: Accepted

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

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

ans = 1

s.sort()

if sum(s)==x:
    print(n)
elif sum(s)<x:
    print(n-1)
else:
    if s[0]>x:
        print(0)
    else:
        for i in range(len(s)):
            if sum(s[:i]) <= x < sum(s[:i+1]):
                print(i)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    rem = x
    ans = 0

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

    if a[n-1] == rem:
        ans += 1

    print(ans)


if __name__ == '__main__':
    main()

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

Submission status: Accepted

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

res=0
i=0
a.sort()

while 0<x and i < n:
    if a[i] <= x:
        res+=1
    x-=a[i]
    i+=1
if 0 < x:
    print(res-1)
else:
    print(res)

Submission status: Accepted

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

a.sort()

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

Submission status: Accepted

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

print(n-1)

Submission status: Accepted

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

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

print(cnt if x <= 0 else cnt-1)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

al.sort()

cnt = 0

for a in al[:N-1]:
  if x >= a:
    x -= a
    cnt += 1
  else:
    break
if al[-1] == x:
  cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

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

Submission status: Accepted

Solution code:
N, x = input().split(' ')
N = int(N)
x = int(x)
a = input().split(' ')
a = [int(a[i]) for i in range(N)]
a = sorted(a)
count = 0
for i in range(N):
  if x - a[i] < 0:
    x -= a[i]
    break
  else:
    x -= a[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()))
ans = 0
if sum(a) == x:
  ans = n
elif x < min(a):
  ans = 0
else:
  if sum(a) < x:
    ans = n - 1
  else:
    a.sort()
    k = 0
    for e in a:
      k += e
      if k <= x:
        ans += 1
      else:
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

i = 0
while True:
    x = x - a[i]
    if x >= 0 and i+1 != len(a):
        i += 1
    elif x == 0 and i+1 == len(a):
        i += 1
        break
    else:
        break

print(i)

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
sum = 0
ans = 0
for i,a in enumerate(A):
    sum += a

    if sum == x:
        ans = i + 1
        break
    elif sum > x:
        break
    elif i + 1 == N and sum < x:
        ans = i
        break
    ans = i + 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-1)
  exit()
cnt = 0
su = 0
for i in range(N):
  if su + a[i] <= x:
    su += a[i]
    cnt += 1
  else:
    break
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N, x = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
i = 0
while i < N:
    if A[i] <= x:
        x -= A[i]
        i += 1
    else:
        print(i)
        sys.exit()
if x > 0:
    print(i - 1)
else:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    N, x = [int(item) for item in input().split()]
    As = [int(item) for item in input().split()]
    As.sort()

    cnt = 0
    while x > 0 and cnt < N:
        x -= As[cnt]
        if cnt == N-1:
            if x == 0:
                cnt += 1
        else:
            if x >= 0:
                cnt += 1
    
    print(cnt)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, x = map(int, input().split())
a = sorted(list(map(int, input().split())))

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    N, x = [int(i) for i in input().split()]
    A = sorted([int(i) for i in input().split()])
    sumA = 0
    cnt = 0
    for i in range(N):
        if A[i] <= (x - sumA):
            sumA += A[i]
            cnt += 1
        else:
            break
    else:
        if sumA != x:
            cnt -= 1
    print(cnt)


resolve()

Submission status: Accepted

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

if sum(A) == x:
    print(N)

else:
    c = 0
    for ai in A:
        x -= ai
        if x <= 0:
            break
        c += 1

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

Submission status: Accepted

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

if sum(A) < x:
    print(N-1)
    exit()

A = [1] + A
ans = 0
while A[-1] <= x:
    x -= A[-1]
    A.pop()
    ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a_list=[int(i) for i in input().split()]

a_list.sort()

if x>sum(a_list):
    print(n-1)

#全員喜ぶ    
elif x==sum(a_list):
    print(n)
    
else:
    sum=0
    count=0
    for i in range(n):
        sum+=a_list[i]
        if sum<=x:
            count+=1
        else:
            break
    print(count)

Submission status: Accepted

Solution code:
from itertools import accumulate

n, x, *aa = map(int, open(0).read().split())

aa.sort()

aa = list(accumulate(aa))

ans = len([a for a in aa if a<=x])
if ans >= 1 and aa[-1]<x:
    ans -=1

print(ans)

Submission status: Accepted

Solution code:
N,x=map(int,input().split())
a=list(map(int,input().split()))
temp=x
ans=0
a.sort()
i=-1
while True:
    i+=1
    x-=a[i]
    if x<0:
        break
    ans+=1
    if ans==N:
        break
if sum(a)<temp:
    ans-=1
    
print(ans)

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
a = sorted(list(map(int,input().split())))
c = 0
ans = 0
i = 0
while x>0 and i<n:
  x -= a[i]
  i += 1
  c += 1
  
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()))

ans = 0
a.sort()
a_sum = [sum(a[:i+1]) for i in range(len(a))]

for i, item in enumerate(a_sum):
    if x < item:
        ans = i
        break
    elif x == item:
        ans = i+1
        break
    elif x > item and i == len(a_sum)-1:
        ans = i
        break

print(ans)

Submission status: Accepted

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

if x > sum(a):
  print(n - 1)
else:
  c = 0
  while x >= a[-1]:
    x -= a.pop()
    c += 1
    if c == n:
      break
  print(c)

Submission status: Accepted

Solution code:
n, x = [int(w) for w in input().split()]
a_li = [int(w) for w in input().split()]
a_li.sort()
 
ans = 0
for a in a_li:
    x -= a
    if x >= 0:
        ans += 1
    else:
        break
 
if x == 0:
    pass
else:
    if x > 0:
        ans = max(ans - 1, 0)
 
print(ans)

Submission status: Accepted

Solution code:
n, x = [int(w) for w in input().split()]
a_li = [int(w) for w in input().split()]
a_li.sort()

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

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

print(ans)

Submission status: Accepted

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

cnt = 0

if x == sum(a_lst):
    print(len(a_lst))
elif x > sum(a_lst):
    print(len(a_lst)-1)
else:
    for i in a_lst:
        x -= i
        if x < 0:
            break
        cnt += 1
    print(cnt)

Submission status: Accepted

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

K=0
for i in range(N-1):
    if x>=A[i]:
        x-=A[i]
        K+=1

if x==A[-1]:
    K+=1

print(K)

Submission status: Accepted

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

Submission status: Accepted

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

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]

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

A.sort()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,X=map(int,input().split())
*A,=map(int,input().split())
A.sort()

ans=0
i=0
while X and i<N-1:
    X-=A[i]
    if X>=0:
        ans+=1
    else:
        break
    i+=1

if i==N-1 and A[i]==X:
    ans+=1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if x == sum(A):
    print(N)
else:
    A.sort()
    ans = 0
    for a in A[:-1]:
        if x >= a:
            ans += 1
            x -= a
        else:
            break
    print(ans)

Submission status: Accepted

Solution code:
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

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

list_sum = [0]
for i in range(N):
    list_sum.append(list_sum[i] + list_N[i])

ans = 0
for i in range(N + 1):
    if list_sum[i] <= x and i < N:
        ans = i
    elif i == N and list_sum[i] == x:
        ans = i


print(ans)

Submission status: Accepted

Solution code:
N,X = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
k1 = k2 = 0
for i in range (N):
  if sum(A[:i+1]) > X:
    k1 = i
    k2 = 1
    break
  elif sum(A) == X:
    k1 = N
    k2 = 1
    break
if k2 == 0:
  k1 = N - 1
print(k1)

Submission status: Accepted

Solution code:
import math 
import numpy
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
for num, val in enumerate(a):
    x -= val
    if x >= 0:
        ans += 1
    else:
        break
else:
    if x > 0:
        ans -= 1
    else:
        pass
print(ans)

Submission status: Accepted

Solution code:
N,X = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
k1 = k2 = 0
for i in range (N):
  if sum(A[:i+1]) > X:
    k1 = i
    k2 = 1
    break
  elif sum(A) == X:
    k1 = N
    k2 = 1
    break
if k2 == 0:
  k1 = N - 1
print(k1)