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 = list(map(int, input().split()))
a.sort()

s = 0
cnt = 0
for i in a:
    s += i
    if s > x:
        break
    cnt += 1

if s < x:
    cnt -= 1    
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a.sort()

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

Submission status: Accepted

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

Submission status: Accepted

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

count = 0
for child in children:
    if x >= child:
        x -= child
        count += 1
    else:
        break
else:
    if x != 0:
        count -= 1

print(count)

Submission status: Accepted

Solution code:
N,x = map(int,input().split())
a = sorted([int(i) for i in input().split()])
ans = 0
for i in a:
  x -= i
  if x >= 0:
    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):
    if sum(A[:i + 1]) > x:
        print(i)
        exit()
    if sum(A[:i + 1]) == x:
        print(i + 1)
        exit()
print(i)

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
List=list(map(int,input().split()))
List.sort()
ans=0
if sum(List)==x:
    print(n)
    exit()
else:
    for i in range(len(List)-1):
        if x>=List[i]:
            ans+=1
            x-=List[i]
        else:
            break
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 i == N-1:
        if x == A[i]:
            ans += 1
        break
    if x >= A[i]:
        x -= A[i]
        ans += 1
    else:
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,x = map(int,input().split())
a = list(map(int,input().split()))
count = 0
#昇順に並べ替える
# sort_a = sorted(a)
a.sort(reverse=False)
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()

Q=0
for i in range(N):
    if x>=a[i] and i!=N-1:
        Q+=1
        x=x-a[i]
    elif i==N-1 and x==a[i]:
        Q+=1
print(Q)

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
s=0
ans=0
for i in range(n):
    s+=a[i]
    if s<=x:
        ans+=1
    else:
        break
if s<x:
    ans=n-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:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N, x = MAP()
a = LIST()

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N, x = MAP()
a = LIST()

a.sort()
A = list(accumulate(a))

n = bisect(A, x)
if n == N and A[-1] < x:
	print(n-1)
else:
	print(n)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
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]:
    x -= a[i]
    count += 1
    if i == n-1 and x > 0:
      print(count-1)
      sys.exit()
    elif i == n-1 and x == 0:
      print(count)
      sys.exit()
  else:
    print(count)
    sys.exit()

Submission status: Accepted

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

s.sort()
cnt = 0

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

if x > 0:
    cnt -= 1

print(cnt)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
# template by 3xC and starkizard.
# contributors: 

#####################################################################################
from __future__ import division, print_function 

import sys
import os
from collections import Counter, deque, defaultdict
import itertools
import math
import io


"""Uncomment modules according to your need"""


# from bisect import bisect_left, bisect_right, insort
# from heapq import heappop, heapify, heappush
# from random import randint as rn
# from Queue import Queue as Q
# from copy import deepcopy
# from decimal import *
# import re
# import operator

#####################################################################################
# this enables you to write python3 code with PyPy2 (Python 2)
if sys.version_info[0] < 3:
    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip

#####################################################################################

"""value of mod"""
MOD = 998244353
mod = 10**9 + 7

"""Uncomment next 4 lines if doing huge recursion"""
# import threading
# threading.stack_size(1<<27)
# sys.setrecursionlimit(10000

def prepare_factorial(mod=mod):
    """ returns two lists, factorial and inverse factorial modulo argument by default 10**9 +7 """
    # Comment code out when you don't need inverse factorial or vice versa
    fact = [1]
    for i in range(1, 200005):
        fact.append((fact[-1] * i) % mod)

    ifact = [0] * 200005
    ifact[200004] = pow(fact[200004], mod - 2, mod)
    for i in range(200004, 0, -1):
        ifact[i - 1] = (i * ifact[i]) % mod

    return fact, ifact

def modinv(n, p):
    """ returns N inverse modulo p """
    return pow(n, p - 2, p)

def ncr(n, r,  fact, ifact):
    """ takes 4 arguments: n , r and factorial and inverse factorial lists"""
    t = (fact[n] * (ifact[r]*ifact[n-r]) % MOD)% MOD
    return t


def get_n(Sum):    
    """this function returns the maximum n for which Summation(n) <= Sum"""
    ans = (-1 + sqrt(1 + 8*Sum))//2
    return ans

def sieve(n):
    """ returns a list of prime numbers till n """
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r



def divs(n, start=1):
    """ returns a list of all divisors till n """
    divisors = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return divisors



def divn(n, primes):
    """ returns the number of divisors, two arguments n and the sieve till n """
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t



def lrfind(d, x, default=-1):
    """ Takes 2 arguments an iterable and an element. returns a tuple (firstoccurence,lastoccurence) -1 if not found """
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return default, default
    else:
        return left, right

def gcd(x, y): # math.gcd is slower
    """ returns greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x

def check_sorted(a):
    ''' returns True/False '''
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
            return False
    return True
def ceil(n, k=1): return n // k + (n % k != 0) #returns math.ceil but protecting against floating inconsistencies
def input(): return sys.stdin.readline().strip()
def ii(): return int(input()) #inputs integer
def mi(): return map(int, input().split()) # inputting space seperated variables for example x,y,z
def li(): return list(map(int, input().split())) #inputting a space seperated list of integers
def lw(): return input().split() #inputting a space seperated list of strings
def lcm(a, b): return abs(a * b) // gcd(a, b) #returns LCM of two arguments
def prr(a, sep=' ', end='\n'): print(sep.join(map(str, a)), end=end) #For printing an iterable with seperator sep as optional second argument (default : " "), ending character (default: "\n") as optional third
def dd(): return defaultdict(int) #returns a dictionary with values defaulted to 0
def ddl(): return defaultdict(list) #returns a dictionary with values defaulted to []
def write(s): return sys.stdout.write(s)












###################################################################
def main():
    #CODE GOES HERE:
    n,x=mi()
    a=li()
    a.sort()
    i=0
    count=0
    while x>0 and i<n-1:
        c=10**9+1
        if a[i]<=x:
            c=min(x,a[i])
            a[i]-=c
            if a[i]==0:
                count+=1
        x=x-c
        i+=1
    if x==a[-1]:
        count+=1
    print(count)
    

















    
""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192

class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill();
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):

    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode('ascii'))
            self.read = lambda: self.buffer.read().decode('ascii')
            self.readline = lambda: self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')

""" main function"""

if __name__ == '__main__':
    main()
    # threading.Thread(target=main).start()

Submission status: Accepted

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

lis.sort()
for i in lis:
    x -= i
    if x >= 0:
        c += 1
    else:
        break

if x > 0:
    c -= 1

print(c)

Submission status: Accepted

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

nums = sorted(list(map(int, input().split())))

count = 0
for i, num in enumerate(nums):
    if (i < n-1 and num <= x) or (i == n-1 and num == x):
        count += 1
        x -= num        
    else:
        break

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    from builtins import int, map, list, print
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    N, x = input_number_list()
    A = input_number_list()
    A.sort()
    ans = 0
    tmp_sum = 0
    for a in A:
        tmp_sum += a
        if tmp_sum > x:
            break
        else:
            ans += 1
    if ans == N and tmp_sum != x:
        ans -= 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

tmp = 0
ans = 0

for a in A:
    tmp+=a
    if tmp<=X:
        ans+=1
if ans==N and tmp<X:
    ans-=1
print(ans)

Submission status: Accepted

Solution code:
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, x, *A = map(int, read().split())
A = sorted(A)
cnt = 0

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

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

print(ans)

Submission status: Accepted

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

A = sorted(A)

i = 0
while i < N:
    if A[i] <= x:
        x -= A[i]
        i += 1
    else:
        break

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

print(i)

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

Submission status: Accepted

Solution code:
N, X = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
res = 0
for a in A:
    if a > X:
        break
    res += 1
    X -= a
else:
    if X > 0:
        res -= 1
print(max(res, 0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
s = [0] * (n+1)
for i in range(n):
    s[i+1] = s[i] + a[i]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

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

    if sum(A) == X:
        print(N)
    else:
        ans = 0
        for a in A[:-1]:
            if a <= X:
                ans += 1
                X -= a
            else:
                break
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N,x = IL()
A = IL()
A.sort()

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

ans = 0
for a in A[:-1]:
  if x >= a:
    x -= a
    ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, X = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]

    A.sort()
    ans = 0
    for a in A:
        if X >= a:
            ans += 1
            X -= a

    if X != 0 and ans == N:
        ans -= 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

if sum(a) == x:
    print(n)
    exit()

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

print(ans)

Submission status: Accepted

Solution code:
def resolve():
    N, x = list(map(int, input().split()))
    a = list(map(int, input().split()))
    dist = []

    ans = 0
    a.sort()

    for i, con in enumerate(a):
        if i == len(a)-1:
            dist.append(x - sum(dist))

        if sum(dist) + con <= x:
            dist.append(con)
        else:
            dist.append(0)

    for i in range(len(a)):
        if a[i] == dist[i]:
            ans += 1
    print(ans)
    return
resolve()

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.buffer.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

def heapsort(iterable):
    h = []
    for value in iterable:
        heapq.heappush(h, value)
    return [heapq.heappop(h) for i in range(len(h))]

n, k = rm()
a = rl()
a = heapsort(a)
cnt = 0
for i in a:
    k -= i
    if k < 0:
        break
    else:
        cnt += 1
else:
    if k != 0:
        cnt -= 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

Solution code:
N,x = map(int,input().split())
a = sorted(list(map(int,input().split())))
s = [sum(a[:i+1]) for i in range(N)]

if s[-1] == x:
  print(N)
  exit()
else:
  for i in range(N-1):
    if s[i] > x:
      print(i)
      exit()
      
  print(N-1)

Submission status: Accepted

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

if sum(li) < x:
    print(n-1)
    exit()

li.sort()
ans = 0

for i in li:
    x -= i
    if x >= 0:
        ans += 1

print(ans)

Submission status: Accepted

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

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

res=0
for a in vA:
	if a<=X:
		res += 1
		X -= a
	else:
		break
else:
	if X:
		res = max(0, res-1)

print(res)

Submission status: Accepted

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

a.sort()

cnt = 0
for i, child in enumerate(a):
    if x == 0:
        break
    if child == x:
        cnt += 1
        break
    if child < x:
        # 最後の要素か判定
        if i == len(a) - 1:
            break
        x -= child
        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 a[i] == x:
    ans+=1
    break
  elif a[i] > x:
    break
  else:
    if i!=(n-1):
      ans+=1
      x-=a[i]
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-1):
    if a[i] > x:
        break
    else:
        x -= a[i]
        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()
ans=-1
num=0
for i in range(n):
    num+=a[i]
    if num>x:
        ans=i
        break
if ans==-1:
    if num==x:
        print(n)
    else:
        print(n-1)
else:
    print(ans)

Submission status: Accepted

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

kids.sort()
i=0
while i<n and x>=kids[i]:
  x-=kids[i]
  i+=1

if x!=0 and i==n:
  i-=1
if i<0:
  i=0
  
print(i)

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
A = sorted([int(i) for i in input().split()])
# print(A)
cnt = 0
for e in A:
    if e <= x:
        x = x - e
        cnt += 1
if cnt == n and x > 0:
    print(cnt-1)
else:
    print(cnt)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 18

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