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: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a.sort()

score = 0
count = N
for i in range(N):
    score+=a[i]
    if score > x:
        count = i
        break

print count

Submission status: Wrong Answer

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

def main():
    n, x = map(int, input().split())
    a_list = list(map(int, input().split()))
    a_list.sort()
    total = 0
    ans = 0
    for i in range(n):
        total += a_list[i]
        if total <= x:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

n,x = ri()
a = sorted(ri())
ans = 0
c = 0
for i in a:
    c += i
    if c>=x:
        break
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N,x = map(int, input().split())
lis = [int(i) for i in input().split()]
lis.sort()
s = 0
ans = 0
for nums in lis:
  if x >= nums:
    x += -nums
    ans += 1
print(ans)

Submission status: Wrong Answer

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

res = 0
for i in a:
    if x<i:
        break
    x -= i
    res += 1
if x==0:
    print(res)
else:
    print(max(res-1,0))

Submission status: Wrong Answer

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

A.sort()

R = 0

for a in A:
    if a <= x:
        R += 1
        x -= a
    else:
        break

print(R)

Submission status: Wrong Answer

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
    X -= A[i]
  else:
    break
    
print(ans)

Submission status: Wrong Answer

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
    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: Wrong Answer

Solution code:
N,X = map(int,input().split())
src = list(map(int,input().split()))
src.sort()

x = 0
ans = 0
for a in src:
    if x+a > X: break
    ans += 1
    x += a
print(ans)

Submission status: Wrong Answer

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

a.sort()

ans = 0
for ai in a:
    if ai <= amount:
        amount -= ai
        ans += 1

print(ans)

Submission status: Wrong Answer

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

n,x = ri()
a = sorted(ri())
ans = 0
c = 0
for i in a:
    c += i
    if c>x:
        break
    ans += 1
print(ans)

Submission status: Wrong Answer

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:
    # do a prefix
    ans=0
    a.sort()
    for i in range(n):
        if x>=a[i]:
            x-=a[i]
            ans+=1
    print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Time Limit Exceeded

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

a.sort()
count = 0

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

Submission status: Time Limit Exceeded

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

if x > 0:
    ans -= 1

print(ans)

Submission status: Time Limit Exceeded

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

a.sort()

for i in a:
    if i >x:
        break
    cou +=1
    x -= i
    
while x>0:
    for i in a:
        if x%i ==0:
            cou -=1
            break
        while x > i:
            x-=i
        cou -= 1
print(cou)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n,x=map(int,input().split())
a=list(map(int, input().split()))
if sum(a)<x:
    print(len(a)-1)
else:
    ans=0
    for i in range(1,n+1):
        for v in itertools.combinations(a,i):
            if sum(v)<=x:
                ans=len(v)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,x = map(int,input().split())
a = [int(i) for i in input().split()]
flag = False
for bit in range(1<<n):
    ans = []
    for i in range(n):
        mask = 1<<i
        if mask&bit:
            ans.append(a[i])
    if sum(ans)==x:
        flag = True
        break
if not flag:    
    a_new = sorted(a)
    i = 0
    while x>=0 and i < n:
        if x >= a_new[i]:
            x -= a_new[i]
        else:
            break
        i += 1
    if x>0 and i>0:
        i -= 1
    print(i)
else:
    print(len(ans))

Submission status: Time Limit Exceeded

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

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

count = 0

for y in a:
    amari = x - y
    while amari >= 0:
        count += 1


print(count)

Submission status: Time Limit Exceeded

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
happy=[]
for i in range(2**n):
    cnt=0
    ans=0
    for j in range(n):
        if ((i>>j)&1):
            cnt+=a[j]
            ans+=1
    if cnt==x:
        happy.append(ans)
    elif cnt<x:
        if 1<=ans:
            happy.append(ans-1)
        else:
            happy.append(0)
print(max(happy))

Submission status: Time Limit Exceeded

Solution code:
N,x=map(int,input().split())
a=list(input().split())
Y=0
import itertools
A=[1,0]
B={}
max=0
for i in itertools.product(A, repeat=N):
  B[i]=i.count(1)

  
for i in reversed(range(N+1)):
  for k, v in B.items():
      if v==i:
        sum=0
        for j in range(N):
          sum=sum+k[j]*int(a[j])
        if sum==x:
          max=i
          Y=1
          break
        if Y==2:
          Y=1
          break
        if sum<x and i>0:
          max=i-1
          Y=2 
  if Y==1:
    break

print(max)

Submission status: Time Limit Exceeded

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

ans = 0
use_list = []
for i in range(2**N):
    use_list.append(list(map(int, list(bin(i)[2::].zfill(N)))))
for u in use_list:
    s = 0
    
    for i in range(N):
        if u[i] == 1:
            s += a[i]
    if s < x:
        ans = max(ans, sum(u)-1)
    elif s == x:
        ans = max(ans, sum(u))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def memoize(f):
    table = dict()
    def wrapper(x, i, a):
        key = (x, i)
        if key in table:
            return table[key]
        else:
            v = f(x, i, a)
            table[key] = v
            return v
    return wrapper

@memoize
def solve(x, i, a):
    if i == len(a) - 1:
        if a[i] == x:
            return 1
        else:
            return 0

    if x < a[i]:
        return 0
    else:
        m = solve(x - a[i], i + 1, a) + 1
        n = solve(x, i + 1, a)
        return max(m, n)

def main():
    n, x = [int(s) for s in input().split()]
    a = tuple(sorted(int(s) for s in input().split()))

    print(solve(x, 0, a))

main()

Submission status: Time Limit Exceeded

Solution code:
import sys


# n = int(sys.stdin.readline().strip())
#
# line = sys.stdin.readline().strip()
# values = list(map(int, line.split()))


def main():
    line = sys.stdin.readline().strip()
    values = list(map(int, line.split()))
    N, x = values[0], values[1]
    line = sys.stdin.readline().strip()
    values = list(map(int, line.split()))
    values = sorted(values)
    d = {}
    d = [[-1 for j in range(x+1)] for i in range(N+1)]

    def rec(i, j):
        res = 0
        if d[i][j] >= 0:
            return d[i][j]
        if i == N:
            if j == 0:
                return 0
            else:
                return -1
        elif j < values[i]:
            res = rec(N, j)
        else:
            res = max(rec(i + 1, j), rec(i + 1, j - values[i]) + 1)
        d[i][j] = res
        return res

    res = rec(0, x)
    if res == -1:
        print(0)
    else:
        print(res)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys


# n = int(sys.stdin.readline().strip())
#
# line = sys.stdin.readline().strip()
# values = list(map(int, line.split()))


def main():
    line = sys.stdin.readline().strip()
    values = list(map(int, line.split()))
    N, x = values[0], values[1]
    line = sys.stdin.readline().strip()
    values = list(map(int, line.split()))
    d = {}
    d = [[-1 for j in range(x+1)] for i in range(N+1)]

    def rec(i, j):
        res = 0
        if d[i][j] >= 0:
            return d[i][j]
        if i == N:
            if j == 0:
                return 0
            else:
                return -1
        elif j < values[i]:
            res = rec(i + 1, j)
        else:
            res = max(rec(i + 1, j), rec(i + 1, j - values[i]) + 1)
        d[i][j] = res
        return res

    res = rec(0, x)
    if res == -1:
        print(0)
    else:
        print(res)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

N, V = list(map(int, input().split()))
C = list(map(int, input().split()))
assert len(C)==N

W = [1 for i in range(N)]
F = [0 for i in range(V+1)]

def pack01(F, c, w):
    """
    f: states
    c: cost
    w: value

    v: volume
    """
    for v in range(c, V+1)[::-1]:
        F[v] = max(F[v], F[v-c]+w)
for i in range(N):
    pack01(F, C[i], W[i])

s = sum(C)
if s==V or s>V:
    print(F[-1])
elif sum(C)<V:
    print(F[-1]-1)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == "__main__":
    N,x = list(map(int, input().split()))
    a = list(map(int, input().split()))
    A = 0

    a.sort()
    while x >= 0:
        try:
            if a[-1] < x:
                x -= a.pop(-1)
                A += 1
        except:
            break

    if x != 0:
        A -= 1
    print(A)

Submission status: Time Limit Exceeded

Solution code:
def memoize(f):
    table = dict()
    def wrapper(x, a):
        key = (x, a)
        if key in table:
            return table[key]
        else:
            v = f(x, a)
            table[key] = v
            return v
    return wrapper

@memoize
def solve(x, a):
    if len(a) == 0:
        return 0

    if len(a) == 1:
        if a[0] == x:
            return 1
        else:
            return 0

    if x < a[0]:
        return solve(x, a[1:])
    else:
        m = solve(x - a[0], a[1:]) + 1
        n = solve(x, a[1:])
        return max(m, n)

def main():
    n, x = [int(s) for s in input().split()]
    a = tuple(int(s) for s in input().split())

    print(solve(x, a))

main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

for i in range(N - 1, 0, -1):
    for element in itertools.combinations(a, i):
        if sum(element) <= x:
            print(i)
            exit()

print(0)
exit()

Submission status: Time Limit Exceeded

Solution code:
def solve(x, a):
    if len(a) == 0:
        return 0

    if len(a) == 1:
        if a[0] == x:
            return 1
        else:
            return 0

    if x < a[0]:
        return solve(x, a[1:])
    else:
        m = solve(x - a[0], a[1:]) + 1
        n = solve(x, a[1:])
        return max(m, n)

def main():
    n, x = [int(s) for s in input().split()]
    a = [int(s) for s in input().split()]

    print(solve(x, a))

main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.append(0)
comb=list(itertools.combinations_with_replacement(a,n))
ans=[]
for i in comb:
    per=sum(i)
    if per==x:
        if 0 in i:
            ans.append(len(set(i))-1)
        else:
            ans.append(len(set(i)))
if len(ans)==0:
    print(0)
else:
    print(max(ans))

Submission status: Accepted

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

Submission status: Accepted

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

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

a = sorted(a)
if x < a[0]:
    print(0)
    exit()

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

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

ans = cnt 
print(ans)

Submission status: Accepted

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

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

a = sorted(a)
if x < a[0]:
    print(0)
    exit()

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

if al: 
    if x > 0:
        ans = cnt-1
    else:
        ans = cnt 
else:
    ans = cnt 

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a = sorted(a)

M = []
cn = 0

for i in range(N):
    x = x - a[i]


    
    if x >= 0 and i != N-1: 
        cn = cn + 1
    elif x < 0:
        print(cn)
        break
    elif i == N-1:
        if x == 0:
            cn = cn + 1
            print(cn)
            break
        else:
            print(cn)
            break

Submission status: Accepted

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

A.sort()

for i, a in enumerate(A):
  x -= a
  if x == 0:
    print(i+1)
    exit()
  elif x < 0:
    print(i)
    exit()
print(N-1)

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0
a.sort()

while x > 0:
    if cnt >= N:
        if x > 0:
            cnt -= 1
            break
        else:
            break
    elif a[0] > x:
        break
    else:
        tmp = a.pop(0)
        x -= tmp
        cnt+=1


print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

arr.sort()
ans = 0

for i in arr:
    x -= i
    if x < 0:
        break
    else:
        ans += 1
if x > 0 and ans > 0:
    ans -= 1

print(ans)

Submission status: Accepted

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

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

count = 0

while(len(A)) != 1:
    x -= min(A)
    if x < 0:
        break
    A.remove(min(A))
    count += 1
    if len(A) == 1:
        if x - min(A) == 0:
            count += 1

print(count)

Submission status: Accepted

Solution code:
# import math
# import statistics
# import itertools
# a=int(input())
# b,c=int(input()),int(input())
# c=[]
# for i in a:
#     c.append(int(i))
A,B= map(int,input().split())
f = list(map(int,input().split()))
# g = [input().split for _ in range(a)]
# h = []
# for i in range(a):
#     h.append(list(map(int,input().split())))
# a = [[0] for _ in range(H)]#nizigen

okasi=B
f.sort()
ans=0
for i in range(A):
    if B>=f[i]:
        B=B-f[i]
        ans+=1
    else:
        if B==okasi:
            ans=0
        break
    if B>0 and i==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()
i = 0
n = 0
for gift in a:
  n += 1
  x -= gift
  if n < len(a):
    if x < 0:
      break
    else:
      i += 1
  elif n == len(a):
    if x == 0:
      i += 1
    else:
      break


print(i)

Submission status: Accepted

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

for i in range(n):
    acsum.append(acsum[i] + a[i])

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

Submission status: Accepted

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

for i in a:
    if x > i:
        x -= i
        cnt += 1
    elif x == i:
        cnt += 1
        break
    else:
        break
else:
    cnt -= 1

print(cnt)

Submission status: Accepted

Solution code:
# coding: utf-8

def main():
    _, x = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()

    ans = 0

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

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

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

num_lists.sort()
cnt = 0
sum = 0
for i in range(len(num_lists)):
    sum += num_lists[i]
    if sum <= x:
        cnt = i+1
    else:
        x = 0
        cnt = i
        break
x -= sum

if 0 < x:
    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 a in A:
    x-=a
    if x>=0:
        ans+=1
    else:
        break

if x>0:
    ans-=1

print(ans)

Submission status: Accepted

Solution code:
# from itertools import accumulate
import itertools

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

B = list(itertools.accumulate(sorted(A))) # cumsum
C = list(itertools.accumulate(sorted(A, reverse=True))) # cumsum

if B[-1] == x:
    print(len(A))
elif B[-1] < x:
    x -= B[-1]
    print(N - (len(list(itertools.takewhile(lambda e: e <= x, C))) + 1))
elif x < B[-1]:
    print(len(list(itertools.takewhile(lambda e: e <= x, B))))

Submission status: Accepted

Solution code:
import itertools

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

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

cnt = 0

for i in range(len(a)):
    if x > a[i]:
        if i == len(a)-1:
            break
        cnt += 1
    elif x == a[i]:
        cnt += 1
        break
    else:
        break

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
a = [int(x.strip()) for x in input().split()]
a_sorted = sorted(a)
ch,ans = 0,0
for i in range(n):
  ch = sum(a_sorted[:i+1])
  if ch < x:
    ans += 1
  elif ch == x:
    ans += 1
    break
  else:
    break
if n == ans and sum(a) < 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

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

Submission status: Accepted

Solution code:
import sys
import copy
a = [int(c) for c in input().split()]
N=a[0]
x=a[1]
a = [int(c) for c in input().split()]
a.sort()
for i in range(N):
    x-=a[i]
    if x<0:
        print(i)
        sys.exit(0)
    elif x==0:
        print(i+1)
        sys.exit(0)

print(N-1)

Submission status: Accepted

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

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

  print(num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
a = [int(s) for s in input().split()]
count = 0

a.sort()
for i in range(n):
    if x >= a[i] and i < n - 1:
        x -= a[i]
        count += 1
    elif x == a[i] and i == n - 1:
        count += 1
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    children=[]
    n,x = map(int,input().split())
    children=list(map(int,input().split()))
    sorted_chiledren=sorted(children)
    counter=0
    last=x

    if sum(children) == x:
        print(n)
        exit()
    elif min(children) > x:
        print(0)
        exit()

    for idx,data in enumerate(sorted_chiledren):
        if data < last:
            last-=data
            counter+=1
            if idx+1==n:
                print(counter-1)
                exit()
        elif data == last:
            counter+=1
            print(counter)
            exit()
        else:
            print(counter)
            break

    
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
a_l = list(map(int, input().split()))
a_l = sorted(a_l)
ans = 0
for a in a_l:
    x = x-a
    if x < 0:
        break
    ans += 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()))
sum_A = sum(A)

if sum_A == x:
    print(N)
elif sum_A < x:
    print(N-1)
else:
    A = sorted(A)
    cnt = 0
    for a in A:
        x -= a
        if x >= 0:
            cnt += 1
        else:
            print(cnt)
            break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from bisect import bisect
from itertools import accumulate

n,x=nii()
a=lnii()
a.sort()

b=list(accumulate(a))

if b[-1]<x:
  print(n-1)
else:
  inx=bisect(b,x)
  print(inx)

Submission status: Accepted

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from bisect import bisect

n,x=nii()
a=lnii()
a.sort()

b=[0]
for i in range(1,n+1):
  b.append(a[i-1]+b[i-1])
b=b[1:]

if b[-1]<x:
  print(n-1)
else:
  inx=bisect(b,x)
  print(inx)

Submission status: Accepted

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,x=nii()
a=lnii()
a.sort()

a_sum=0
for i in range(n):
  a_sum+=a[i]
  if a_sum>x:
    print(i)
    exit()

if x>sum(a):
  print(n-1)
else:
  print(n)

Submission status: Accepted

Solution code:
from sys import stdin

n, x = [int(x) for x in stdin.readline().split()]
a_lst = sorted([int(x) for x in stdin.readline().split()])
s = 0

for i, a in enumerate(a_lst):
  s += a
  if s > x:
    print(i)
    exit()
    
if s == x: print(i+1)
else: print(i)

Submission status: Accepted

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

for s in S:
  X -= s
  if X >= 0:
    cnt += 1
  else:
    break

if X > 0:
  cnt -= 1
    
print(cnt)

Submission status: Accepted

Solution code:
# A - Candy Distribution Again
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 or (ans==N-1 and x!=0):
        break
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
# A - Candy Distribution Again
N,x = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
tmp = 0
ans = 0
for a in A:
    tmp += a
    if tmp<=x:
        ans += 1
    else:
        break
if ans==N and tmp!=x:
    ans -= 1
print(ans)

Submission status: Accepted

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

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

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

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

print(max(ans, 0))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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