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 = sorted(a)
counter = 0
for i in range(n):
    x -= a[i]
    if x == 0 and i == 0:
        counter +=1
    elif x > 0 and 0 <= i <= n-2:
        counter +=1
    elif x == 0 and i == n-1:
        counter +=1
print(counter)

Submission status: Accepted

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

a_list.sort()

def func():
    cnt = 0
    global x
    for a in a_list:
        if x>=a:
            x -= a
            cnt += 1
        else:
            return cnt
    if x==0:
        return cnt
    else:
        return cnt-1

print(func())

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from collections import defaultdict, deque
import math
from math import factorial
import fractions
import re

BIGNUM = 10 ** 9 + 7

def main():
    N, x = map(int, input().split())
    As = list(map(int, input().split()))

    As = sorted(As)
    total = 0
    num = 0
    for a in As:
        if total+a <= x:
            total += a
            num += 1
        else:
            break

    if num == N and total != x:
        num -= 1
    print(num)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

a.sort()

c = 0
sum = 0
for b in a:
    if sum + b <= x:
        c += 1
        sum += b
    else:
        break
if c == N and sum != x:
    c -= 1
print(c)

Submission status: Accepted

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

count = 0
for i in range(n):
    x -= sorted(a_list)[i]
    if i < n - 1 and x >= 0:
        count += 1
    elif i == n - 1 and 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()], reverse=True)

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

Submission status: Accepted

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


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, typ=int):
    return [typ(input()) for _ in range(n)]


def main():
    n, x = read_h()
    a = sorted(read_h())

    cnt = 0
    rem = x
    for ai in a:
        rem -= ai
        if rem < 0:
            break
        cnt += 1

    if rem > 0:
        cnt -= 1

    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
row = input().split()
N = int(row[0])
x = int(row[1])

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

if x <= 0:
    print(count)
else:
    print(count-1)

Submission status: Accepted

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

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:
        print(cnt)
        exit()
    if s==x:
        print(cnt+1)
        exit()
    cnt+=1
if s == x:
    print(cnt)
else:
    print(cnt-1)

Submission status: Accepted

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

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

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

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

a.sort()


now=x
cnt=0
for i in range(n):
    now -=a[i]
    cnt +=1
    if now<0:
        cnt -=1
        print(cnt)
        exit()

if now==0:
    print(cnt)
else:
    print(cnt-1)

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
a_sorted = sorted(a)
total = 0
happy = 0
for v in a_sorted[:-1]:
  total += v
  if total <= x:
    happy += 1 
if sum(a) == x:
  happy = len(a)
print(happy)

Submission status: Accepted

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


def solve(N: int, x: int, a: "List[int]"):
    ans = 0
    a.sort()
    for i in a:
        if(x-i >= 0):
            ans += 1
            x -= i
        else:
            break
    else:
        if(x > 0):
            print(ans-1)
            exit()

    print(ans)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, x, a)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

a.sort()

cnt = 0

for i in range(n):
    if i == n-1 and a[i] < x:
        break    
    if a[i] <= x:
        cnt += 1
        x -= a[i]

        

print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

if sum(a) < x:
  ans=n-1
elif  sum(a) == x:
  ans=n
else:
  i=0
  val=0
  while val <= x:
    val+=a[i]
    i+=1
#    print(i,x)
  ans=i-1
  
print(ans)

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
num = 0
if sum(a) < x:
    print(n-1)
elif a[-1] > x:
    print(0)
else:
    while x > 0:
        x = x - a.pop()
        if x >= 0:
            num += 1
    print(num)

Submission status: Accepted

Solution code:
import numpy as np
N,x = map(int,input().split())
A = np.array(input().split(), dtype = np.int64)
A.sort()
np.cumsum(A, out = A)
answer = (A <= x).sum()

if answer == N and A[-1] != x:
  answer -= 1
print(answer)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ans=0
ch=list(map(int,input().split()))
ch.sort()
if m>sum(ch):
  print(n-1)
else:
  sum=0
  i=0
  while sum<m and ans!=n:
    sum+=ch[ans]
    ans+=1
    if sum > m:
      ans-=1
      break
  print(ans)

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
a = list(map(int, input().split()))
num = len(a)
a.sort(reverse=True)
for i in range(num):
    x -= a.pop()
    if x < 0:
        print(i)
        exit()
    if x == 0:
        print(i + 1)
        exit()
print(num - 1)

Submission status: Accepted

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

Submission status: Accepted

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

#a_sort = sorted(a, reverse=True)
a_sort = sorted(a)
#print(a_sort)
manzoku =0
flag = 0
for n,i in enumerate(a_sort):
    if x>=i:
      x-=i
      #print(x)
      manzoku+=1
#      print(x,i)
    elif x<i:
      flag =1
      
    

if  flag:
    print(manzoku)
elif flag==0 and(x>0) and (manzoku>0):
    print((manzoku)-1)
else:
    print(manzoku)

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 a[i] <= x:
        cnt += 1
    x -= a[i]

if x > 0:
    cnt -= 1

print(max(0, cnt))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
A - Candy Distribution Again
https://atcoder.jp/contests/agc027/tasks/agc027_a

"""
import sys


def solve(N, x, A):
    ans = 0
    for a in A:
        if x >= a:
            ans += 1
            x -= a
    if ans == N and x != 0:
        return ans-1
    return ans


def main(args):
    N, x = map(int, input().split())
    A = sorted([int(a) for a in input().split()])
    ans = solve(N, x, A)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
N, x = map(int,input().split())
A = sorted(list(map(int, input().split())))
ans = 0
su = 0
for i, A_i in enumerate(A):
	if su + A_i <= x:
		ans = i + 1
		su += A_i
	else:
		break
if sum(A) < x:
	ans -= 1
print(max(0, ans))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

A.sort()

for i in range(N):
    sum_s += A[i]
    if sum_s > x:
        s = i
        break

if sum_s < x:
    print(N - 1)
elif sum_s == x:
    print(N)
else:
    print(s)

Submission status: Accepted

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

N, X = map(int, input().split())
L = [int(v) for v in input().split()]
L.sort()

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

if ans == N and X > 0:
    ans -= 1
    
print(ans)

Submission status: Accepted

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

a.sort()
result = 0
for candy in a:
    if x - candy < 0:
        break
    result += 1
    x = x - candy
else:
    if x > 0:
        result -= 1
print(result)

Submission status: Accepted

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

c, x = 0, X
for a in A:
	if x < a:
		break
	c += 1
	x -= a
else:
	if x:
		c -= 1

print(c)

Submission status: Accepted

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

Submission status: Accepted

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

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

if x == 0:
    print(n)
elif x > 0:
    print(n-1)
else:
    print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import exit, stdin
N, X = [int(_) for _ in stdin.readline().rstrip().split()]
A = [int(_) for _ in stdin.readline().rstrip().split()]
A.sort()
ans = 0
for i in range(N):
  if A[i] <= X:
    X -= A[i]
    if i == N-1 and X == 0:
      ans += 1
    elif i != N-1:
      ans += 1
  else:
    print(ans)
    exit()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

aaa.sort()
ans = 0
for a in aaa:
  if a > x:
    break
  ans += 1
  x -= a
else:
  if x > 0:
    ans -= 1
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#方針 N人に配っても余っている場合は一人にすべて押し付けることで最大値を求める


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

sort_a = sorted(a)

cnt = 0
sum_a = 0
for i in sort_a:
    x -= i
    if x >= 0:
        cnt += 1
    else:
        break

if x > 0:
    cnt -= 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

        else:
            break
    

print(ans)

Submission status: Accepted

Solution code:
# 2019/05/21
# AtCoder Grand Contest 027 - A

# For the Answer:
# 1. リストを昇順ソート
# 2. 小さい方から足していく
# 2-1. xと等しくなったら、答え
# 2-2. xを超えたら、最後の1個で満足するのがいるか探索(いなければ-1)
# 2-3. nまで足しても等しくなければ、-1

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

# 1.
a.sort()

#2. 
acm = 0
ans = -1
for i in range(n):
    acm += a[i]
    # 2-1.
    if acm == x:
        ans = i + 1
        break
    # 2-2.
    elif acm > x:
        wk_acm = acm - a[i]
        j = i + 1
        while j < n:
            if wk_acm + a[j] == x:
                ans = i + 1
                break
            j += 1
        if j >= n:
            ans = i
        break

# 2-3.
if i == n - 1 and x != acm:
    ans = n - 1

# Output
print(ans)

Submission status: Accepted

Solution code:
N,x=map(int,input().split())
t=list(map(int,input().split()))
if x > sum(t):
    print(N-1)
else:
    cnt=0
    total=0
    t=sorted(t)
    for T in t:
        total+=T
        if total <= x:
            cnt+=1
        else:
            break
    print(cnt)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
hoge=list(map(int,input().split()))
hoge.sort()

if(sum(hoge)<m):
  print(n-1)
  exit()

ans=0
for i in range(n):
  if(hoge[i]<=m):
    ans+=1
    m-=hoge[i]
  else:
    break
print(ans)

Submission status: Accepted

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

for i in range(1, N+1):
    if sum(A[:i]) == x:
        print(i)
        quit()
    if sum(A[:i]) > x:
        print(i-1)
        quit()
print(N - 1)

Submission status: Accepted

Solution code:
from bisect import bisect_right

n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
SUM = [a[0]]

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

if SUM[-1] < x:
    print(n-1)
else:
    print(bisect_right(SUM, x))

Submission status: Accepted

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

    else:
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate

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

A.sort()

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

Submission status: Accepted

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

i = 0

while (i<N) and (x>=0):
    x -= a[i]
    if x>=0:
        i += 1

if (i == N) and (x>0) :
    print(N-1)
else:
    print(i)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort()
calc = 0
ans = 0
for i, aa in enumerate(a):
    calc += aa
    if calc > x:
        break
    else:
        ans += 1
if (i == n-1) & (ans == x):
    ans += 1
if calc < x:
    ans = i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
n,x=map(int,input().split())
A=[int(i) for i in input().split()]
A.sort()
S=[]
s=0
for i in range(n):
  s+=A[i]
  S.append(s)
k=bisect.bisect(S,x)
if k<n and x==S[k]:
  k+=1
if k==n and x!=S[-1]:
  k-=1
print(k)

Submission status: Accepted

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

from itertools import accumulate
Acumsum = list(accumulate(A))

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

if i==N and Acumsum[-1]!=x:
    print(N-1)
else:
    print(i)

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

Submission status: Accepted

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

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

print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,x,*a=map(int,open(0).read().split())
s=0
for c in sorted(a):
  if x>=c and s<n-1:
    s+=1
  elif x==c and s==n-1:
    s+=1
  x-=c
  if x<=0:break
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
cnt = 0
for a in A:
    if a <= x:
        cnt += 1
    x -= a
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(reverse=True)
if x > sum(a):
    print(n-1)
    exit()
if x == sum(a):
    print(n)
    exit()
for i in range(n):
    a.pop(0)
    if len(a) == 0:
        print(0)
        exit()
    if x >= sum(a):
        print(n-i-1)
        exit()

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0
for i, a in enumerate(sorted(A)):
    if a <= x:
        if i == N - 1 and a < x:
            break
        else:
            cnt += 1
            x -= a
    else:
        break

print(cnt)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
a,b=map(int, input().split())
c=[int(i) for i in input().split()]
c.sort()
ans=0
for i in c:
    b=b-i
    if b>=0:
        ans=ans+1
if b>0:
    ans=ans-1
print(ans)

Submission status: Accepted

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

m_list=sorted(list_)

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

    print(ans)

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
fav = sorted(map(int, input().split()))
oura=[int()]*N

oura[0] = fav[0]
for i in range(len(fav)-1):
    oura[i+1] = oura[i] + fav[i+1]


sai = 0
for j in range(len(oura)):
    if oura[j] > x:
        sai = j
        break
    elif j != N-1:
        continue
    elif oura[N-1] == x:
        sai = N
    else:
        sai = N-1

print (sai)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,x = map(int, input().rstrip().split())
a = list(map(int, input().rstrip().split()))
a.sort()
counter = 0
for i,n in enumerate(a):
    x -= n
    if x >= 0 and i != N-1:
        counter += 1
    elif x == 0:
        counter += 1
        break
    else:
        break
print(counter)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if x == sum(a_):
  print(N)
else:
  sum_a = 0
  for i in range(N):
    if x >= sum_a + a_[i]:
      sum_a += a_[i]
    else:
      break
  print(i)

Submission status: Accepted

Solution code:
def main():
    N,x = map(int,input().split())
    num = x
    a_s = list(map(int,input().split()))
    a_s.sort()
    cnt = 0
    for i,a in enumerate(a_s):
        if num >= a:
            num -= a
            cnt += 1

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