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:
N, X = map(int, input().split())
A = sorted(map(int, input().split()))
ans = 0
for a in A:
    if X < a:
        break
    X -= a
    ans += 1
if ans == N and X != 0:
    ans -= 1
print(ans)

Submission status: Accepted

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

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

a = sorted(a)
ans = 0
f = 1
for i in range(n):
    x -= a[i]
    if x<0:
        f = 0
        break
    ans += 1
    
if x != 0 and f == 1:
    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 a in A[:-1]:
  if x >= a:
    ans += 1
    x -= a
if x == A[-1]:
  ans += 1
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, x, A):
    A.sort()
    ans = 0
    for a in A:
        x -= a
        if x >= 0:
            ans += 1
        else:
            break
    else:
        if x != 0:
            ans -= 1
    return ans


def main():
    # N = read_int()
    N, x = read_int_n()
    A = read_int_n()
    print(slv(N, x, A))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# encoding:utf-8
import numpy
import bisect
 
def main():
	n, x = list(map(int, input().split()))
	nums = list(map(int, input().split()))

	nums.sort()
	cum_nums = numpy.cumsum(nums)

	if x > cum_nums[-1]:
		print(n - 1)
	else:
		idx = bisect.bisect_right(cum_nums, x)
		print(idx)


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search of Tree (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


# --------------------------------------------

dp = None


def main():
    N, x = li_input()
    A = sorted(li_input())

    ans = 0

    for i, a in enumerate(A):
        if x >= a:
            if i != N - 1 or i == N-1 and x == a:
                x -= a
                ans += 1

    print(ans)


main()

Submission status: Accepted

Solution code:
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


N, x = inpl()
A = inpl()
A.sort()
tmp = 0
for i in range(N):
    tmp += A[i]
    if tmp > x:
        ans = i
        break
else:
    if tmp == x:
        ans = N
    else:
        ans = N - 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N-1):
    if x >= a_list[i]:
        res += 1
        x -= a_list[i]
    else:
        break
if x == a_list[N-1]:
    res += 1
    
print(res)

Submission status: Accepted

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

A.sort()

ans = 0

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

if x > 0:
    ans -= 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,x= map(int,input().split())
a = [int(_) for _ in input().split()]
a.sort()
a = a[::-1]
ans = 0
while x > 0:
  if a == []:
    ans -= 1
    break
  y = a.pop()
  x-= y
  if x >= 0:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
n,x=[int(k) for k in raw_input().split(" ")]

a=[int(k) for k in raw_input().split(" ")]

a=sorted(a)

nbh=0

for i in a:
    if i<=x:
        x-=i
        nbh+=1
    else:
        break
if x and nbh==n:
    nbh-=1

print nbh

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]



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


a.sort()

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

print(ans)

Submission status: Accepted

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

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

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

ans = 0
for i, a in enumerate(As):
    if i != N - 1:
        if x >= a:
            ans += 1
            x -= a
    else:
        if x == a:
            ans += 1
            
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline
mii=lambda:map(int,input().split())

n,x=mii()
a=list(mii())


if sum(a)==x:
    print(n)
else:
    # not possible to satisfy all
    # do a prefix
    ans=0
    a.sort()
    for i in range(n-1):
        if x>=a[i]:
            x-=a[i]
            ans+=1
    print(ans)

Submission status: Runtime Error

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


if sum(a)<x:
    print(N-1)
else:
    for i in range(len(A)):
        if X>=a[i]:
            x -= a[i]
            ans += 1
        else:
            break

Submission status: Runtime Error

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

s=0
num=0
for i in range(len(a)):
  if x>=a[i]:
    x-=a[i]
    num+=1
  else:
    break
    
print(num)

Submission status: Runtime Error

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

a.sort()

s=0
i=0

if sum(a)<=x:
    print(n)
    exit()
elif min(a)>x:
    print(0)
    exit()
else:
    while s<x:
        s+=a[i]
        i+=1

print(i-1)

Submission status: Runtime Error

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

a.sort()

s=0
i=0

if sum(a)<=x:
    print(n)
    exit()
elif min(a)>x:
    print(0)
    exit()
else:
    while s<x:
        s+=a[i]
        i+=1

print(s)
print(i-1)

Submission status: Runtime Error

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

a.sort()

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

@jit
def main(n, x, a):
  cnt = 0
  for i in a:
    x -= i
    if x <= 0:
      break
    elif i == a[-1] and x > 0:
      break
    cnt += 1
  return cnt

n, x = map(int, readline().split())
a = np.sort(np.array(readline().split(), np.int64))
print(main(n, x, a))

Submission status: Runtime Error

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

a.sort()
count = 0

for i in a:
    if x >= a[min]:
        x -= i
        count += 1
    else:
        pass
        
print(count)

Submission status: Runtime Error

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

a.sort()
count = 0

while x > min(a):
for i in a:
    if x >= i:
        x -= i
        count += 1
    else:
        pass
        
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,x = input().split()
A = input().split()
a = []
for i in range(int(N)):
  a.append(int(A[i]))
  
a.sort()
a.append(1)
X = int(x)
 
idx = 0
while X>=0:
  X = X-a[idx]
  idx+=1

print(idx-1)

Submission status: Runtime Error

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

a.sort()
a.reverse()
X = int(x)

idx = 0
while X>0:
  X = X-a[idx]
  idx+=1
  
print(idx)

Submission status: Runtime Error

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

Solution code:
N,x=map(int,input().split())
a=list(map(int,input().split()))
b=sorted(a)
c=0
while True:
  if sum(a)==x:
    print(N)
    break
  elif b[c]<=x:
    x=x-b[c]
    c+=1
  else:
    if sum(a)<x:
      print(c-1)
    else:
      print(c)
    break

Submission status: Runtime Error

Solution code:
N,x=map(int,input().split())
a=list(map(int,input().split()))
b=sorted(a)
c=0
while True:
  if sum(a)==x:
    print(N)
    break
  elif b[c]<=x:
    x=x-b[c]
    c+=1
  else:
    print(c)
    break

Submission status: Runtime Error

Solution code:
N,x=map(int,input().split())
a=list(map(int,input().split()))
b=sorted(a)
c=0
while True:
  if sum(a)==x:
    print(N)
    break
  elif b[c]<=x:
    x=x-b[c]
    c+=1
  else:
    print(c-1)
    break

Submission status: Runtime Error

Solution code:
N,x=map(int,input().split())
a=list(map(int,input().split()))
b=sorted(a)
c=0
while True:
  if sum(b)==x:
    print(N)
    break
  elif b[c]<=x:
    x=x-b[c]
    c+=1
  else:
    break
print(c)

Submission status: Runtime Error

Solution code:
N,x=map(int,input().split())
a=list(map(int,input().split()))
b=sorted(a)
c=0
while True:
  if sum(b)==x:
    print(x)
    break
  elif b[c]<=x:
    x=x-b[c]
    c+=1
  else:
    break
print(c)

Submission status: Runtime Error

Solution code:
N,x=map(int,input().split())
a=list(map(int,input().split()))
b=sorted(a)
c=0
while True:
  if sum(b)=x:
  print(x)
  break
  elif b[c]<=x:
    x=x-b[c]
    c+=1
  else:
    break
print(c)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
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: Runtime Error

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:
        s += 1

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

Submission status: Runtime Error

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
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
    elif x > item and i == len(a_sum):
        ans = i

print(ans)

Submission status: Runtime Error

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

a.sort()
i = 0
c = 0
while x > 0:
    if x >= a[i]:
        c += 1
    x -= a[i]
    i += 1
print(c)

Submission status: Runtime Error

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

a.sort()
i = 0
c = 0
while x > 0:
    if x >= a[i]:
        c += 1
    x -= a[i]
    i += 1
print(c)

Submission status: Runtime Error

Solution code:


Submission status: Runtime Error

Solution code:
for i in range(N):
    print(i)
    if x >= sort_a[i]:
        count += 1
        x -= sort_a[i]
        # print(x)
        continue
    break
print(count)

Submission status: Runtime Error

Solution code:
N,x = map(int,input().split())
# a=[int(input()) for i in range(4)]
a = list(map(int,input().split()))
count = 0
#昇順に並べ替える
sort_a = sorted(a)

for i in range(len(N)):
    if x >= sort_a[i]:
        count += 1
        x -= sort_a[i]
    break
print(count)

Submission status: Runtime Error

Solution code:
N,x = map(int,input().split())
# a=[int(input()) for i in range(4)]
a = list(map(int,input().split()))
count = 0
#昇順に並べ替える
sort_a = sorted(a)

for i in range(len(N)):
    if x >= sort_a[i]:
        count += 1
        x -= sort_a[i]
        print(x)
        continue
    break
print(count)

Submission status: Runtime Error

Solution code:
N,x = map(int,input().split())
a=[int(input()) for i in range(N)]
# a = list(map(int,input().split()))
count = 0
#昇順に並べ替える
sort_a = sorted(a)

for i in range(len(a)):
    if x >= sort_a[i]:
        count += 1
        x -= sort_a[i]
        continue
    break
print(count)

Submission status: Runtime Error

Solution code:
N,x = map(int,input().split())
hito = input()
poo = [hito]
zyun = sorted(hito)
ok = 0
for i in range(len(poo)):
	if x-zyun[i]>=0:
      ok+=1
    else:
      print(ok)

Submission status: Runtime Error

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

a.sort()

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

Submission status: Runtime Error

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

l = sorted(a)
flag = False
for i in range(n):
    x -= l[i]
    if x < 0:
        flag = True
        break
if flag:
    print(i)
elif x = 0:
    print(n)
elif x > 0:
    print(n - 1)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,x,*a=map(int,open(0).read().split())
a.sort()
s=0
i=0
while s<x or i<=n:
    i+=1
    s+=a[i]
print(~-i)

Submission status: Runtime Error

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

A.sort()
ans = 0

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

Submission status: Runtime Error

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

A.sort()
ans = []
for i in A:
	if x < i:
		break
	ans += 1
	x -= i
	else:
		break

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

Submission status: Runtime Error

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

A.sort()
ans = []
for i in A:
	if x < i:
		break
	ans += 1
	x -= i
else:
	break

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

Submission status: Runtime Error

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

A.sort()
ans = []
for i in A:
	if x < i:
		break
	ans += 1
	x -= i

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

Submission status: Runtime Error

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

for i in a:
  if x - i >= 0:
    x -= i
    count += 1
if x > 0 and count != 0 and p >= a.sum() :
  count -= 1
print(count)

Submission status: Runtime Error

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

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




print(ans-1)

Submission status: Runtime Error

Solution code:
N,X = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a)
m = sum(a)
count = 0
S=0
if m == X:
    print(N)
elif m < X:
    print(N-1)
elif a[0] > X:
    print(0)
else: 
    for i in a:
        if S < X:
            S = S + i
            count = count + 1
    else:
        print(count-1)
N,X = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a)
m = sum(a)
count = 0
S=0
if m == X:
    print(N)
elif m < X:
    print(N-1)
elif a[0] > X:
    print(0)
else: 
    for i in a:
        if S <= X:
            S = S + i
            count = count + 1
    else:
        print(count-1)

Submission status: Runtime Error

Solution code:
n,x=int(input().split())
N=list(map(int,input().split()))
K=sorted(N,reverse=True)
if sum(K)<=x:
  print(n)
  sys.exit()
for i in range(1,n+1):
  if sum(K)-K[0]<=x:
    print(n-i)
    sys.exit()
  else:
    K.pop(0)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,x = [int(hoge) for hoge in input().split()]
A = [int(hoge) for hoge in input().split()]
#x個のお菓子を配る。
#和がxを越えないように最も多い数のaを選ぶ
A.sort()
ans = 0
cur = 0
for a in A:
    cur += a
    if cur > x:
        print(ans)
        exit()
    ans += 1
if cur == X:print(N)
else:print(ans-1)

Submission status: Runtime Error

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

t = a.pop()
ans = 0
while x>=t:
  ans+=1
  x-=t
  t=a.pop()
  
print(ans)

Submission status: Runtime Error

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

while sum < x:
    sum += a_list[num]
    num += 1
    
print(num)

Submission status: Runtime Error

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

while sum < x:
    sum += a_list[num]
    num += 1
    print(sum)
    
print(num)

Submission status: Runtime Error

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

while sum < x and num <= N:
    sum += a_list[num]
    num += 1
    
print(num)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

S = 0
c = 0

for i in range(N):
  S += A[i]
  
if S < x:
  print(N-1)
else:
  for i in range(N):
    b = x - A[i]
    if b > 0:
      c += 1
      x -= A[i]
    elif b == 0:
      count += 1  
      break
    else:
      break
  print(c)

Submission status: Runtime Error

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

if ans == N:
  rest = cumsum[N] - x
  if rest != 0:
    ans -= 1

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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: Runtime Error

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

now=0
for i in l:
    now+=i;d.append(now)
from bisect import bisect_left as bl,bisect_right as br

print(max(0,br(d,x)-1+(sum(l)==x)))

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
s=0
while True:
  if m>=a[s]:
    m-=a[s]
    s+=1
  else:break
print(s)

Submission status: Runtime Error

Solution code:
3 3
dxx
axx
cxx

Submission status: Runtime Error

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


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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

list_a.sort()
total = sum(list_a)
if x < list_a[0] :
    print(0)
    exit()
if x > total :
    print(ans-1)
    exit()
ans = 0

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

print(ans)

Submission status: Runtime Error

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

lst.sort(reverse = True)
cnt = 0

while x > lst[cnt]:
  x -= lst[cnt]
  cnt += 1
  
print(cnt)

Submission status: Runtime Error

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

children.sort()
sum = 0

for i in children:
    sum += i

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

Submission status: Runtime Error

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

children.sort()
sum = 0

for i in children:
    sum += i

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

Submission status: Runtime Error

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

cont = 0

for i in sorted(a):
    x -= i
    if x >= 0:
        cont += 1
    else:
        break

if x > 0:
    cont -= 1

print(cont)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n, x = LI()
    a = LI()
    a.sort()
    for ai in a:
        x -= ai
        if x < 0:
            break
        ans += 1
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
from sys import stdin, exit
import itertools
#stdin = open("input.txt")

if __name__ == "__main__":
    N, K = [int(item) for item in stdin.readline().split()]
    li = [int(item) for item in stdin.readline().split()]
    
    li.sort()
    
    if sum(li) == K:
        print(N)
    elif sum(li) < K:
        print(N-1)
    else:
        cumsum = itertools.accumulate(li)
        index = [i for i, item in enumerate(cumsum) if item<=K]
        print(index[-1] + 1)

Submission status: Runtime Error

Solution code:
A,B = map(int,input().split())
X =list(map(int,input().split()))
X = sorted(X)
count = 0
if B == sum(X):
  print(len(X))
elif B >= min(x):
  print(0)
else:
  for i in range(A):
    a = X.pop(0)
    B=B - a
    if B >= 0:
      count += 1
  print(count)

Submission status: Runtime Error

Solution code:
import math
import heapq
import sys
from collections import Counter

#N,K=map(int, input[0].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#x=list(map(int, input[1].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

N,x=map(int, input[0].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
a=list(map(int,input[1].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

heapq.heapify(a)  # リストを優先度付きキューへ

for i in range(N):
    x-=heapq.heappop(a)  # 最小値の取り出し
    #print(x,a)
    if x<=0 or i==N-1:
        print(i+1)
        break

Submission status: Runtime Error

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split() for i in range(n)))
a_sort=sorted(a)
count=0
sum=0
for i in a_sort:
    while sum+i<=x:
        sum=sum+i
        count+=1
    else:
        break
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a_sort =sorted(a)
cou = 0
for i in range(N):
    if x >= a_sort[i]:
        cou += 1
        x -= a_sort[i]
print(cou)

Submission status: Runtime Error

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

a.sort()

ans=0
tmp=0
for i in  range(len(a)):
  tmp+=int(a[i])

if tmp==x:
  print(N)
  exit()

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

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