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.

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

ans = 0
s = 0
for i in range(n):
    s += a[i]
    if x < s:
        break
    elif i < n - 1 or s == x:
        ans += 1
print(ans)

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

Solution (Python):
I = lambda: [int(i) for i in input().split()]
n,k=I()
a=I()
a.sort()
s=0
for i in a:
  k-=i
  if k>=0:
    s+=1
  if k<=0:
    break
else:
  s-=1
print(s)

Solution (Python):
n,x = map(int,input().split())
ass = list(map(int,input().split()))
ass.sort()

ans = 0
acm = 0
for i in ass:
    acm += i
    if x >= acm:
        ans +=1

if acm < x:
    ans -= 1

print(ans)

Solution (Python):
import sys

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

S=[None]*N
S[0]=A[0]

if A[0]>x:
    print(0)
    sys.exit()

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

if S[i]==x:
    print(N)
else:
    print(i)

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

a.sort()

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

Solution (Python):
INF = 999999999999999999L
EPS = 1e-12

def read():
    return raw_input().strip()

def read_ints():
    return map(int,read().split())

n,x = read_ints()
a = read_ints()
a.sort()
ans = 0
for i in range(len(a)):
    if i == len(a)-1 and x == a[i]:
        ans += 1 
    elif i != len(a)-1 and a[i] <= x:
        ans += 1 
        x -= a[i] 
print ans

Solution (Python):
def ii():
    return int(input())
def mi():
    return map(int, input().split())
def li():
    return list(mi())

N, x = mi()
a = li()
a.sort()
c = 0
for ai in a:
    if x < ai:
        break
    x -= ai
    c += 1
if c == N and x > 0:
    c -= 1
print(c)

Solution (Python):
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from itertools import accumulate
from bisect import bisect_right

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

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


if x == a_cum[-1]:
    print(n)

elif x > a_cum[-1]:
    print(n-1)
    
else:
    ans = bisect_right(a_cum, x)
    print(ans)

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

if ans == n and b[-1] != x:
	ans -= 1
print(ans)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):

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, x = read_int_n()
    A = read_int_n()
    print(slv(N, x, A))


if __name__ == '__main__':
    main()

Solution (Python):

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

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(1000000)



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



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



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



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

Solution (Python):


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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):



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)

Solution (Python):


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)

Solution (Python):

import sys

input=sys.stdin.readline
mii=lambda:map(int,input().split())

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


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

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