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

count = 0
san = sorted(an)
for a in san:
    x -= a
    if x < 0:
        break
    count += 1
if x > 0:
    count -= 1

print(count)

Submission status: Accepted

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

if sum(alist) == x:
  print(n)
else:
  suma = 0
  k = 0
  for a in alist:
    if suma <= x:
      suma += a
      k += 1
  print(k - 1)

Submission status: Accepted

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

a.sort()
count = 0
for ai in a:
    if x >= ai:
        x -= ai
        count += 1
    else:
        x = 0
if x > 0:
    count -= 1

print(count)

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:
    if X-a < 0: break
    X -= a
    ans += 1
else:
    if X:
        ans -= 1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
""" AtCoder """

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

print(ans)

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
a.reverse()
ans=0
while x>0:
  if x==0:
    break
  elif len(a)==0:
    ans-=1
    break
  if a[-1]<=x:
    x-=a.pop()
    ans+=1
  else:
    break
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N, x = map(int, input().split())
a = np.array(list(map(int, input().split())))
a.sort()
s = np.cumsum(a)
b = (s <= x)
if b.all():
  if s[-1] == x:
    c = b.sum()
  else:
    c = b.sum() - 1
elif b.any():
  c = b.sum()
  r = x - s[c-1]
  if (r == a[c:]).any():
    c += 1
else:
  c = 0
print(c)

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

Submission status: Accepted

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

a = sorted(a)

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#AGC027 A
'''
問題
N人の子供がいる
x個のお菓子をすべて配り切らなければならない
お菓子をもらわないこどもがいてもよい
子供iはちょうどai個のおかしをもらうと喜ぶ
喜ぶ子供の人数の最大値は?

考察
aiを小さい順にソートし,xから順番にaiを引いていく
'''

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

ans = 0

for a in A:
	if x>=a:
		ans += 1
		x -= a
	elif x<a:
		break

#お菓子が最終的に余った場合の処理
if ans==N and x>0:
	ans -= 1

print(str(ans))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort()
frag = False
count = 0
for i in range(len(a)):
    if x >= a[i]:
        count += 1
        x -= a[i]
    else:
        frag = True
        break
if not frag and x != 0:
    count -= 1
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

A = sorted(A)

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

if x > 0 and ans == N:
  ans -= 1
elif x > 0 and ans < N:
  pass
print(ans)

Submission status: Accepted

Solution code:
def solve():
    N,x=map(int,input().split())
    a=list(map(int,input().split()))
    a=sorted(a)
    ans = 0
    for i,ai in enumerate(a):
        x -= ai
        if x == 0:
            return i + 1
        elif x < 0:
            return i
    return N - 1

print(solve())

Submission status: Accepted

Solution code:
N, x = [int(j) for j in input().split()]
a = sorted(list(map(int, input().split())))
sum = 0
flag = True

for i in range(N):
    sum += a[i]
    if sum > x:
        flag = False
        break

if sum != x:
    flag = False
    
print(i+1 if flag else i)

Submission status: Accepted

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

Submission status: Accepted

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

a=[int(i) for i in input().split()]

a.sort()
i=0
ans=0

while x>0 and i<n:
    if x-a[i]>=0:
        x-=a[i]
        ans+=1
    else:
        x=0
    if i==n-1:
        if x>0:
            ans-=1
    i+=1

print(ans)

Submission status: Accepted

Solution code:
N, x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
for i in range(len(a)):
    sum_a = sum(a[:i+1])
    if sum_a > x: #何人目までには配れるかの条件式、i人目までの合計を足していく
        print(i)
        break
if sum(a) == x: #全員に配れる場合
    print(N)
elif sum(a) < x: #全員には配れない(一番要求数が多いやつだけにはあげられない)
    print(N-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

N,x = inpl()
A = sorted(inpl())

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
childs = list(map(int, input().split()))
if(m > sum(childs)):
    print(len(childs)-1)
else:
    count = 0
    childs.sort()
    for child in childs:
        if m >= child:
            m -= child
            count += 1
    print(count)

Submission status: Accepted

Solution code:
N,x = map(int,input().split())
l = list(map(int,input().split()))
l.sort()
for i in range(len(l)):
    sum_l = sum(l[:i+1])
    if sum_l > x :
        print(i)
        break
if sum(l) == x:
    print(N)
elif sum(l) < x:
    print(N-1)

Submission status: Accepted

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

an = sorted(an)

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

Submission status: Accepted

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

ass = sorted(ass)

count =0
for i,a in enumerate(ass):
	if i == len(ass)-1:
		if a < x:
			break
		elif a == x:
			count+=1
			break
		else:
			break
			
	if x < a:
		break
			
	
	x -= a
	count += 1
	
print(count)

Submission status: Accepted

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

Submission status: Accepted

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


if __name__=="__main__":
    main()

Submission status: Accepted

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

sum_a = sum(srt_a)
if sum_a == x:
    # ちょうど全員喜ぶ
    ans = N
elif sum_a < x:
    # N-1 人喜ぶ。ある一人に残りの飴を全部押し付ける
    ans = N - 1
else:
    # 喜ぶ数の少ない順に配れば、喜ぶ人数が最大化される
    cnt = 0
    while True:
        a = srt_a[cnt]
        if x >= a:
            x -= a
            cnt += 1
        else:
            break
    ans = cnt

print(ans)

Submission status: Accepted

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

s = sum(A)
if s == X:
    print(N)
else:
    ans = 0
    A = sorted(A)
    for i in range(N-1):
        if sum(A[:i+1]) <= X:
            ans = i+1
            
    print(ans)

Submission status: Accepted

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

rest = x
i = 0
cnt = 0

while rest > 0 :
    if rest < a[i] :
        break
    rest -= a[i]
    i += 1
    if (i == N) :
        if (rest == 0) :
            cnt += 1
        break
    cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

while x > sum and i < n:
    sum += a[i]
    i += 1

if sum == x:
    print(i)
else:
    print(i-1)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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


aList.sort()

total_child = 0
isEqual = False
for a in aList:
    if x == 0:
        isEqual = True
        break
    elif x < 0:
        break
    x -= a
    total_child += 1

    if x == 0:
        isEqual = True

if isEqual:
    print(total_child)
else:
    print(total_child - 1)

Submission status: Accepted

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

score = 0
for a in aList:
    if x >= a:
        x -= a
        score += 1
    else:
        break

if x > 0:
    if score == len(aList):
        score -= 1
print(score)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Candy Disribution Again

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

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

Submission status: Accepted

Solution code:
import itertools
import numpy as np
import sys
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,num = IL()
a = IL()

a.sort()

cnt = 0
for i in range(N):
    if i != N-1:
        if num-a[i] > 0:
            num -= a[i]
            cnt += 1
        elif num-a[i] == 0:
            cnt += 1
            break
    else:
        if num-a[i] == 0:
            cnt += 1
print(cnt)

Submission status: Accepted

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

A.sort()
RA = []
q = 0
for i in range(n):
    q += A[i]
    RA.append(q)

if RA[-1] < x:
    ans = n - 1
elif RA[-1] == x:
    ans = n
elif RA[0] > x:
    ans = 0
else:
    for i in range(n):
        if RA[i] == x:
            ans = i + 1
            break
        elif RA[i] > x:
            ans = i
            break

print(ans)

Submission status: Accepted

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

count = 0
for a in a_list:
  x -= a
  count += 1
  if x < 0:
    break

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

Submission status: Accepted

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

a.sort()

Ans = N
for i in range(N):
  x -= a[i]
  if x < 0:
    Ans = i
    break

if Ans == N and x != 0:
  Ans = N - 1

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):
    x -= A[i]
    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()))
a.sort()
ret = 0
for i in a:
    x -= i
    if x < 0:
        break
    ret += 1
if x > 0:
    ret -= 1
print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect

N, x = map(int, input().split())
A = list(map(int, input().split()))
S = [0] * (N + 1)
A.sort()

for i, a in enumerate(A):
    S[i + 1] = S[i] + a

res = bisect.bisect_right(S, x) - 1
if res == N and S[-1] != x:
    print(res - 1)
else:
    print(res)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/agc027/tasks/agc027_a


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

    count = 0
    i = 0
    while x > 0 and i < N:
        if a[i] <= x:
            count += 1
            x -= a[i]
        else:
            break
        i += 1

    if i == N and x != 0:
        count = max(0, count - 1)

    print(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,x=map(int,input().split())
a=[int(y) for y in input().split()]
a.sort()
ans=0
if sum(a)<x:
  ans=N-1
else:
  ans=0
  for i in range(N):
    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 = sorted(list(map(int, input().split())))
count = 0
for i in range(N):
    x -= a[i]
    if 0 == x:
        count += 1
        break
    elif (0 < x) and (i+1 != len(a)):
        count += 1
    else:
        break
print(count)

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

Submission status: Accepted

Solution code:
from sys import stdin
N,x=[int(x) for x in stdin.readline().rstrip().split()]
data=[int(x) for x in stdin.readline().rstrip().split()]
data=sorted(data)
ans=0
if data[0] > x:
    print(0)
else:
    for i in data:
        x=x-i
        if x < 0:
            break
        ans+=1
    if x > 0 and x!=0 and ans !=1:
        ans-=1
    print(ans)

Submission status: Accepted

Solution code:

a=raw_input();
lt=a.split(' ')
n=int(lt[0])
x=int(lt[1])
b=raw_input()
lt=b.split(' ')
ar=[]
for i in range(0,n):
	ar.append(int(lt[i]))

ar.sort()
v=0
for i in range(0,n):
	if x<=0:
		break
	else:
		x-=ar[i]
		v+=1

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate
from bisect import bisect_right
n,x=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
S=list(accumulate(A))
i=bisect_right(S,x)
if i!=n:
    print(i)
else:
    if S[-1]==x:
        print(n)
    else:
        print(n-1)

Submission status: Accepted

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

Submission status: Accepted

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

N, x = map(int, input().split())
aList = map(int, input().split())
sortedAList = sorted(aList)

cnt = 0
for i in range(0, len(sortedAList)):
	if x >= sortedAList[i]:
		if i + 1 != len(sortedAList) or x == sortedAList[i]:
			cnt += 1
			x   -= sortedAList[i]
		else:
			break
	else:
		break
	
print(cnt)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

a_list.sort()
ans = 0
for a in a_list:
  if x < a:
    break
  x = x - a
  ans += 1

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

Submission status: Accepted

Solution code:
a,b= map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
if sum(ar) == b:
    print(a)
elif sum(ar) < b:
    print(a-1)
else:
    br = []
    for r in ar:
        if r <= b:
            br.append(r)
    if len(br) == 0:
        print(0)
    else:
        br = sorted(br,reverse=True)
        while True:
            if sum(br) > b:
                del br[0]
            else:
                print(len(br))
                break

Submission status: Accepted

Solution code:
import bisect

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

A = sorted(A)

for i in range(len(A)-1):
    A[i+1] += A[i]

ans = 0
ind = bisect.bisect_right(A, x)
if ind == 0:
    ans = 0
elif ind >= N:
    if A[-1] == x:
        ans = N
    else:
        ans = N-1
else:
    ans = ind
print(ans)

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

if x > 0:
    ans -= 1

print(ans)

Submission status: Accepted

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

count = 0

for i in range(N):
    if len(a) <= 1:
        if a[0] == x:
            count += 1
        break
    
    n = min(a)
    if x < n:
        break
    
    x -= n
    a.pop(a.index(n))
    count += 1
    
print(count)

Submission status: Accepted

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

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, initial=1)
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, X = MAP()
aN = LIST()

aN.sort()
sm = sum(aN)
if sm < X:
    print(N-1)
elif sm == X:
    print(N)
else:
    x = X
    for i in range(N):
        x -= aN[i]
        if x < 0:
            print(i)
            exit()

Submission status: Accepted

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

li.sort()

child = 0
for a in li:
    x -= a
    if x < 0:
        break
    child += 1
if x > 0:
    child -= 1

print(child)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


def r(n, x, al):
    al.sort()
    for i in range(n):
        if x < al[i]:
            break
        elif x >= al[i]:
            x -= al[i]
        if x == 0:
            i += 1
            break

    return i


def main():
    input = sys.stdin.readline
    n, x = list(map(int, input().split()))
    al = list(map(int, input().split()))
    print(r(n, x, al))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
n, x = map(int, input().split())
kids = list(map(int, input().split()))
kids.sort()
joy = 0
for k in kids:
  if (x >= k):
    x -= k
    joy += 1
  else:
    print(joy)
    sys.exit()
if (x > 0):
  joy -= 1
print(joy)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b=map(int, input().split())
x=list(map(int, input().split()))
x.sort()
x.append("a")
i = 0
r = 0
while b> 0:
    if x[i] == "a":
        r-=1
        break
    b -= x[i]
    if b >= 0:
        i +=1
        r +=1
print(r)

Submission status: Accepted

Solution code:
n, x = map(int, raw_input().split())
a = map(int, raw_input().split())
a.sort()
give = a[::]

for i in range(n):
    if i == n-1:
        give[i] = x
    else:
        give[i] = min(x, a[i])
        x -= give[i]

print sum([give[i] == a[i] for i in range(n)])

Submission status: Accepted

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

a.sort()

ans = 0
temp = 0
for ai in a:
    temp += ai
    if temp <= x:
        ans += 1
    else:
        break

if ans == N:
    if sum(a) != 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()
count = 0

for i in range(n):
    if x > 0:
        x -= A[i]
        count += 1
        
if x != 0:
    count -= 1
    
print(count)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def ii():
    return int(input())


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


N, X = il()
A = sorted(il())
if X == sum(A):
    print(N)
    exit()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#Begginer027

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

A.sort()
candy = 0
ans = 0
for i in A:
    candy += i
    if candy <= x:
        ans += 1
if candy < x:
    ans -= 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

A.sort()
count = 0

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

if len(A) == count and x > 0:
    count -= 1

print(count)

Submission status: Accepted

Solution code:
# _*_ coding:utf-8 _*_
#  Atcoder_Grand_Contest027-a
#  https://atcoder.jp/contests/agc027/tasks/agc027_a

def  countJoyChild(haveCookie,joyMeterList):
	joyMeterList.sort()
	childsCount = len(joyMeterList)
	sendCookieRangeMax = range(0,childsCount,+1)
	sendCookieChilds = 0
	for i in sendCookieRangeMax :
		haveCookie = haveCookie-joyMeterList[i]
		if 0 <= haveCookie:
			sendCookieChilds = sendCookieChilds + 1
		else:
			break
	if 0 < haveCookie: # => 最後の一人が多すぎる
		sendCookieChilds = sendCookieChilds - 1

	answer = sendCookieChilds
	return answer


if __name__ == '__main__':
	_,X = map(int,input().strip().split(' '))
	A = list(map(int,input().strip().split(' ')))
	solution=countJoyChild(X,A)
	print("{}".format(solution))

Submission status: Accepted

Solution code:
# _*_ coding:utf-8 _*_
#  Atcoder_Beginners_Contest-
#  Atcoder_Grand_Contest-
#  TODO https://atcoder.jp/contests/abc/tasks/abc_
import time
from contextlib import contextmanager
# from time import sleep
@contextmanager
def timer(title):
	t0 = time.time()
	yield
	print("{} - done in {:.0f}s".format(title,time.time()-t0) )

def  countJoyChild(haveCookie,joyMeterList):
	joyMeterList.sort()
	childsCount = len(joyMeterList)
	sendCookieRangeMax = range(0,childsCount,+1)
	sendCookieChilds = 0
	for i in sendCookieRangeMax :
		haveCookie = haveCookie-joyMeterList[i]
		if 0 <= haveCookie:
			sendCookieChilds = sendCookieChilds + 1
		else:
			break
	if 0 < haveCookie: # => 最後の一人が多すぎる
		sendCookieChilds = sendCookieChilds - 1

	answer = sendCookieChilds
	return answer


if __name__ == '__main__':
	_,X = map(int,input().strip().split(' '))
	A = list(map(int,input().strip().split(' ')))
#	with timer("countJoyChild"):
	solution=countJoyChild(X,A)
	print("{}".format(solution))

Submission status: Accepted

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