Problem:


Score : 200 points

Problem Statement

There are N children, numbered 1, 2, ..., N.

Snuke has decided to distribute x sweets among them.
He needs to give out all the x sweets, but some of the children may get zero sweets.

For each i (1 \leq i \leq N), Child i will be happy if he/she gets exactly a_i sweets.
Snuke is trying to maximize the number of happy children by optimally distributing the sweets.
Find the maximum possible number of happy children.

Constraints

All values in input are integers.

2 \leq N \leq 100

1 \leq x \leq 10^9

1 \leq a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N x
a_1 a_2 ... a_N

Output

Print the maximum possible number of happy children.

Sample Input 1

3 70
20 30 10

Sample Output 1

2

One optimal way to distribute sweets is (20, 30, 20).

Sample Input 2

3 10
20 30 10

Sample Output 2

1

The optimal way to distribute sweets is (0, 0, 10).

Sample Input 3

4 1111
1 10 100 1000

Sample Output 3

4

The optimal way to distribute sweets is (1, 10, 100, 1000).

Sample Input 4

2 10
20 20

Sample Output 4

0

No children will be happy, no matter how the sweets are distributed.



Sample input:
3 70
20 30 10


Sample output:
2

Submission status: Accepted

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

a.sort()
ans = 0

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

Submission status: Accepted

Solution code:

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

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

if ans == 0:
	print(ans)
elif x == 0:
	print(ans)
else:
	print(ans-1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
N, x=input().split()
N=int(N)
x=int(x)
#x=[]
#y=[]
#t, x, y = [0]*(N+1), [0]*(N+1), [0]*(N+1)#N+1個の空のリストを作成(原点を入れて##るから一つ増える)
#delta_t=0
#delta_x=0
#delta_y=0
#l=0
#t[0],x[0],y[0]=[0, 0, 0]
#とりあえず入力までは完成した．
#for i in range(N):
# t[i+1], x[i+1], y[i+1] = map(int, input().split())
child_i =  list(map(int, input().split()))
#w_len=len(w)
#w_list=list(w)
#print(len(w_list))
#print(w_list)
child_il=sorted(child_i)
#print(child_il)#リストの右端のほうが大きい
i=0
j=0
for i in range(N):
 x=x-child_il[i]
 if x < 0:
    print(j)
    sys.exit()
 elif i==N-1 and x!=0:
    break 
 else:
     j=j+1

print(j)

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

Submission status: Accepted

Solution code:


def main()->None:
    (N, x) = map(int, input().split())
    a = list(map(int, input().split()))
    sorted_a = sorted(a) # 小さい順にならべる
    count = 0 # 何回配ったか
    for d in sorted_a:
        x -= d
        if x < 0:
            break
        count += 1
    # ちょうど配れない、必要な量より多く持ってた時
    if x > 0:
        print(count-1)
    else:
        print(count)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:


def main()->None:
    (N, x) = map(int, input().split())
    a = list(map(int, input().split()))
    sorted_a = sorted(a) # 小さい順にならべる
    count = 0 # 何回配ったか
    for d in sorted_a:
        x -= d
        if x < 0:
            break
        count += 1
    # ちょうど配れない、必要な量より多く持ってた時
    if (count == N) and (x > 0):
        print(count-1)
    else:
        print(count)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

A.sort()

y, i = 0, 0
while y < x and i < N:
  y += A[i]
  i += 1
if y > x or (y < x and i == N):
  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):
  x-=a[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 = list(map(int, input().split()))

a.sort()
goukei = 0
count = 0

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

print(count)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
child = sorted(list(map(int, input().split())))
count = 0

for i in range(a - 1):
    if b >= child[i]:
        b -= child[i]
        count += 1
if b == child[-1]:
        count += 1

print(count)

Submission status: Accepted

Solution code:
import sys

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 s == x:
        print (i + 1)
        sys.exit()

    elif s > x:
        print (i)
        sys.exit()

print (N-1)

Submission status: Accepted

Solution code:
n,x,*a=map(int,open(0).read().split())
a.sort()
b,c=0,0
for i in a:
    if b+i<=x:
        b+=i
        c+=1
print(c-1*(sum(a)<x))

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

if x == a[-1]:
    ans += 1

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

array.sort()
s = sum(array)

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
a_s = map(int, input().split())
sorted_a_s = sorted(a_s)
rest_snaks = x
satisfied_num = 0
for n in range(N):
    if sorted_a_s[n] <= rest_snaks:
        if n == (N-1):
            rest_snaks -= sorted_a_s[n]
            if rest_snaks == 0:
                satisfied_num += 1
        else:
            satisfied_num += 1
        rest_snaks -= sorted_a_s[n]
    else:
        rest_snaks = 0

print(satisfied_num)

Submission status: Accepted

Solution code:
import sys

def main():
  N, x = map(lambda i: int(i), input().split(' '))
  a = list(map(lambda i: int(i), input().split(' ')))
  a.sort()
  answer = 0
  for i in range(N):
    if x >= a[i]:
      x -= a[i]
      answer += 1
    else:
      print(answer)
      sys.exit()
  print(answer if x == 0 else answer - 1)

main()

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,x = inpl()
a = inpl()
a.sort()
for i in range(n):
    if a[i] <= x:
        x -= a[i]
    else:
        print(i)
        break
else:
    if x == 0:
        print(n)
    else:
        print(n-1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans=count=0

n,x=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
for i in range(n-1):
    ai=A[i]
    if x>=ai:
        x-=ai
        count+=1
if A[n-1]==x:
    count+=1
print(count)

Submission status: Accepted

Solution code:
n, x = [int(x) for x in input().split()]
children = [int(x) for x in input().split()]
children.sort()
for i, child in enumerate(children):
    if x < child or (i==len(children)-1 and x!=child):
        print(i)
        break
    else:
        x -= child
else:
    print(len(children))

Submission status: Accepted

Solution code:
# AGC027
N, x = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
ans = 0
cnt = 0
if x > sum(A):  #お菓子が多い時は最後の一人に残った分をあげる
    print(N-1)
    exit()
if x == sum(A): # ちょうどのとき
    print(N)
    exit()
if x < A[0]:    # 誰も満足させれない
    print(0)
    exit()
# 複数人満足させられる時
for i in range(N):
    if x >= A[i]:
        x -= A[i]
    else:
        ans = i
        break
print(ans)

Submission status: Accepted

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

l = sorted([int(i) for i in input().split()])
total = sum(l)

if total == m:
    print(n)
elif total < m: 
    print(n-1)
else:
    ct = 0
    for i in l:
        if m >= i:
            ct += 1
            m -= i
        else:
            break
    print(ct)

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

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

li.sort()
ans = 0

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

Submission status: Accepted

Solution code:
import math
import heapq
import sys
from collections import Counter

#N,K=map(int, input[0].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#x=list(map(int, input[1].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

N,x=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
a=list(map(int,input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

heapq.heapify(a)  # リストを優先度付きキューへ

for i in range(N):
    x-=heapq.heappop(a)  # 最小値の取り出し
    #print(x,a)
    if x<=0 or i==N-1:
        if x==0:
            print(i+1)
        else:
            print(i)
        break

Submission status: Accepted

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

N, x = list(map(int, input().split()))
a_list = list(map(int, input().split()))
a_list = sorted(a_list)
# xよりaが大きい子供にはどう頑張っても配りようがないので最初から除外する
a_list = [a for a in a_list if a <= x]
count = 0
d_list = [0] * N

# 少ない子から順に配っていく
for i, a in enumerate(a_list):
    if i == N - 1:
        # 最後の一人だったら全部押し付ける
        d_list[i] = x
        break

    if x - a >= 0:
        d_list[i] = a
        x -= a
    else:
        d_list[i] = x
        break

ans = len([a for a, d in zip(a_list, d_list) if a == d])

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

Submission status: Accepted

Solution code:
import bisect
import itertools
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n, x = ril()
ls = sorted(ril())
acc = list(itertools.accumulate(ls))
i = bisect.bisect(acc, x)
if i == len(acc):
    if x > acc[-1]:
        i -= 1
print(i)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

    a.sort()

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

    if i == n - 1 and a[i] == x:
        i += 1

    print(i)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,x = inpl()
a = inpl()
a.sort()
if sum(a) < x:
    print(n-1)
else:
    s = 0
    for i,y in enumerate(a):
        # print(i,y)
        if s + y < x:
            s += y
        elif s + y == x:
            print(i+1)
            break
        else:
            print(i)
            break
    else:
        print(n-1)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,x = inpl()
a = inpl()
a.sort()
if a[0] > x:
    print(0)
elif sum(a) == x:
    print(n)
elif sum(a) < x:
    print(n-1)
else:
    s = 0
    for i,y in enumerate(a):
        # print(i,y)
        if s + y < x:
            s += y
        elif s + y == x:
            print(i+1)
            break
        else:
            print(i)
            break
    else:
        print(n-1)

Submission status: Accepted

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

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

if x == a[n-1]:
    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()

tmp_total_a = 0
count_happy = 0
for a in a_list:
    tmp_total_a += a
    if tmp_total_a <= x:
        count_happy += 1
    else:
        break

if tmp_total_a < x:
    count_happy -= 1
    
print(count_happy)

Submission status: Accepted

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

count = 0
for i in sorted(a):
    if x >= i:
        x -= i
        count += 1
    # else:
    #     break
if x > 0 and count == n:
    count -= 1
print(count)

Submission status: Accepted

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

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

if(x == a[N - 1]):
  r += 1

print(r)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

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

Submission status: Accepted

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

a_L = list(sorted(a_L))

counter = 0
for val in range(n):
    if x - a_L[val] >= 0 and val != n-1:
        counter += 1
        x = x-a_L[val]

    if x - a_L[val] == 0 and val == n-1:
        counter +=1
        break

print(counter)

Submission status: Accepted

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

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

ans=0

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

Submission status: Accepted

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

for ai in a:
    sum_a+=ai
    if sum_a<=x:
        ans+=1

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

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

Submission status: Accepted

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

A.sort()
s = 0
ans = 0
while ans < n and s <= x:
    s += A[ans]
    ans += 1

if s != x:
    ans -= 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,x=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)

count=0
while len(A)>1:
    temp=A.pop(-1)
    if temp>x:
        break
    else:
        count+=1
        x-=temp

temp=A.pop(-1)

if x==temp:
    print(count+1)
else:
    print(count)

Submission status: Accepted

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

for A in a:
    if x >= A:
        c += 1
        x -= A
if c == N and x != 0:
    c -= 1
print(c)

Submission status: Accepted

Solution code:
N, X = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
last_index = len(A) - 1
ret = 0
for i, a in enumerate(A):
    if a <= X:
        ret += 1
        X -= a
if ret == N and X > 0:
    ret -= 1
print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

a.sort()
ans = 0

for i in range(N):
    if (x >= a[i] and i < N-1) or (x == a[i] and i == N-1) :
        x -= a[i]
        ans += 1
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
N,x=map(int,input().split())
a=list(map(int,input().split()))
a_sort=sorted(a)
#print(a_sort)
ans=0
b=True
for i in range(N):
  if x-a_sort[i]>=0:
    x-=a_sort[i]
    ans+=1
  else:
    b=False
    break

if b and x>0:
  ans-=1
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)
elif sum(a)==x:
    print(n)
else:
    diff=sum(a)-x
    a.sort(reverse = True)
    cnt=0
    while diff > 0 and cnt < n:
        diff -= a[0+cnt]
        cnt+=1
    print(n-cnt)

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 = sorted(a)
ans = 0
for i in range(n):
    if a[i] <= x:
        ans += 1
        x -= a[i]
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)
elif sum(a) == x:
    print(n)
else:
    a.sort()
    for i, num in enumerate(a):
        if x >= num: x -= num
        else:
            print(i)
            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 range(n):
	x-=a[i]
	if x<0:
		break
	else:
		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())))
ans = 0
for i in a:
    if i > x:
        print(ans)
        exit()
    else:
        ans += 1
        x -= i
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()
if x == sum(a):
    print(N)
elif x > sum(a):
    print(N-1)
else:
    for i in range(N):
        if sum(a[:i+1]) > x:
            print(i)
            break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = list(map(int, input().split()))
c = sorted(c)
count = 0
for i in range(a):
    b = b - c[i]
    if i == a - 1:
        if (b == 0):
            count += 1
    else:
        if (b >= 0):
            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()
sum = 0
count = 0
while True:
  sum += a[0]
  if sum > x:
    break
  count += 1
  del a[0]
  if len(a) == 0:
    break
if x > sum:
  print(count-1)
else:
  print(count)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, x = tuple(map(int, input().split()))
A = list(map(int, input().split()))
A = sorted(A)
count = 0
for a in A[:-1]:
    if a <= x:
        count += 1
        x -= a

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

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

print(ans)

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n, x = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    a.sort()
    cnt = 0
    for v in a:
        x -= v
        cnt += 1
        if x == 0:
            break
        elif x < 0:
            cnt -= 1
            break
    print(cnt if x <= 0 else cnt - 1)


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
# AGC027A - Candy Distribution Again
# greedy algorithm
from itertools import accumulate as acc


def main():
    # maximize the number of proper distribution -> begin with small values
    N, X, *A = map(int, open(0).read().split())
    A.sort()
    ac = list(acc(A))
    if ac[-1] < X:  # the last one receives more than expected -> ans - 1
        ans = N - 1
    else:
        ans = sum(i <= X for i in ac)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

A.sort()
ans=0
for i,a in enumerate(A):
  if i==n-1 and x-a>0:
    break
  elif x-a<0:
    break
  x-=a
  ans+=1
print(ans)

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
m = 0
ans = 0
flag = True
for i in range(N):
  x -= A[i]
  ans += 1
  if x == 0:
    print(ans)
    flag = False
    break
  elif x < 0:
    print(ans-1)
    flag = False
    break
if flag:
  print(ans-1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def resolve():
    n, x = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    for i in range(n):
        if x >= a[i]:
            x -= a[i]
            a[i] = 0
    ans = a.count(0)
    if x and all(ai == 0 for ai in a):
        ans -= 1
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
#ｘは持っている飴のこすう
n,x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
if(sum(a)<x):
    ans -=1


a.sort()

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

print(ans)

Submission status: Accepted

Solution code:
def solve(n, x, a):
    ans = 0
    for v in sorted(a):
        if v <= x:
            ans += 1
            x -= v
    if (x > 0) and (ans == n):
        ans -= 1
    return ans

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def cumsum(inlist):
    s = 0
    outlist = []
    for i in inlist:
        s += i
        outlist.append(s)
    return outlist

n, x = [ int(v) for v in input().split() ]
candy_list = sorted([ int(v) for v in input().split() ])
candy_list_2 = cumsum(candy_list)

ans = 0
for i in range(n):
    if i != n-1 and candy_list_2[i] <= x:
        ans += 1
    elif i == n-1 and candy_list_2[i] == x:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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