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:
from bisect import bisect_right
from itertools import accumulate

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

arr.sort()
arr = list(accumulate(arr))


happy = bisect_right(arr, x)

if happy == n:
    if arr[-1] != x:
        happy -= 1

print(happy)

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

Submission status: Accepted

Solution code:
import sys
n,x = map(int, sys.stdin.readline().rstrip("\n").split())
a = [int(s) for s in sys.stdin.readline().rstrip("\n").split()]
a.sort()
ans = 0
for i in range(n):
    if i == n-1:
        if x - a[i] == 0:
            ans += 1
    else:
        if x-a[i] >= 0:
            x = 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.sort(); b = 0
for i in range(len(a)):
    if x >= a[i]: x -= a[i]; b += 1
    else: break
else:
    if x > 0: b -= 1
print(b)

Submission status: Accepted

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

Submission status: Accepted

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

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

a_sorted = sorted(a)

num = 0
reminder = x
for i in range(N):
    reminder -= a_sorted[i]
    if reminder>=0:
       num += 1
    else:
        break

if reminder>0:
    num -= 1
    
print(num)

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


print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    v = list(map(int, input().split()))
    n = v[0]
    x = v[1]
    a = list(map(int, input().split()))

    # aの値が小さい順にぴったり配っていく
    count = 0
    a = sorted(a)

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
c=list(map(int,input().split()))
c.sort()
i=0
total=0
while True:
    if b<c[i]:
        print(total)
        break
    elif i==a-1:
        if b==c[i]:
            print(total+1)
        else:
            print(total)
        break
    else:
        total+=1
        b=b-c[i]
        i+=1

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# vim: fileencoding=utf-8


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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

ans = 0
for i, v in enumerate(a):
    x -= v
    if i == n - 1:
        if x == 0:
            ans += 1
        break
    else:
        if x >= 0:
            ans += 1
            continue
        else:
            break

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<a[0]:
    print(0)
    exit()


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

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

Submission status: Accepted

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


def main():
    N, x, *A = map(int, open(0).read().split())
    A.sort()
    for i in range(N):
        x -= A[i]
        if x == 0:
            print(i + 1)
            break
        elif x < 0:
            print(i)
            break
    else:
        # ちょうどN個もらわないと喜べない悲しい子どもたち
        print(N - 1)


main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

count = 0
for i, child in enumerate(sorted(child_list)):
  x -= child
  if x < 0:
    break
  if (i == len(child_list) - 1) and x != 0:
    break
  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 a:
  x-=i
  if x>0:
    ans+=1
    continue
  
  elif x==0:
    ans+=1
    break
    
  else:
    break
    
if ans==n:
  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=sorted(a,reverse=False)
tot=0
if sum(a)==x:
    print(len(a))
elif sum(a)<x:
    print(len(a)-1)
else:
    for i in range(N):
        tot+=a_sort[i]
        if tot==x:
            print(i+1)
            break
        elif tot<x:
            pass
        elif tot>x:
            print(i)
            break

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/agc027/tasks/agc027_a
n, x = [int(i) for i in input().split()]
A = sorted([int(i) for i in input().split()])

if sum(A) == x:
    ans = n
elif sum(A) < x:
    ans = n - 1
else:
    ans = 0
    for i in range(n):
        if A[i] <= x:
            if i == n - 1:
                if x == A[i]:
                    ans += 1
            else:
                x -= A[i]
                ans += 1
        else:
            continue

print(ans)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math

#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n,x = readInts()
A = sorted(readInts())
cnt = 0
#print(A)
for i in range(n):
    if x > A[i] and not i == n-1:
        cnt += 1
        x -= A[i]
    elif x == A[i]:
        cnt += 1
        break
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, x, *a = map(int, open(0).read().split())
a.sort()

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

Submission status: Accepted

Solution code:
def LI():
    return list(map(int, input().split()))


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

Submission status: Accepted

Solution code:
N, x, *A = map(int, open(0).read().split())
A.sort()
ans = 0
for a in A[:-1]:
    if x - a >= 0:
        x -= a
        ans += 1
    else:
        break
if x == A[-1]:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
N,x = map(int,input().split())
A = sorted(list(map(int,input().split())))
if x>=2*sum(A):
    print(0)
else:
    ind = N
    for i in range(N):
        x -= A[i]
        if x<0:
            ind = i
            break
    if ind==N and x>0:
        A = sorted(A,reverse=True)
        for i in range(N):
            x -= A[i]
            if x<0:
                ind -= 1
                break
    print(ind)

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

ans=0
for i in range(N):
    if x == 0:
        break
    if x >= a[i]:
        ans+=1
        x-=a[i]
    else:
        x = 0
if x != 0:
    ans -= 1
print(max(0,ans))

Submission status: Accepted

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

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

sort_a = sorted(a)
count = 0
for i in range(1,N+1):
    if sum(sort_a[:i]) <= x:
        if i < N:
            count += 1
        else:
            pass
    else:
        break

print(count)

Submission status: Accepted

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

cnt = 0
flag = False
for i in a:
    if i <= x:
        x -= i
        cnt += 1
        if x == 0:
            break
    else:
        break
else:
    cnt -= 1
print(cnt)

Submission status: Accepted

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

cnt = 0
flag = False
for i in a:
    if i <= x:
        x -= i
        cnt += 1
        if x == 0:
            flag = True
    else:
        break
else:
    if not flag:
        cnt -= 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

c=0
for i in l:
  x-=i
  if x<0:
    c+=1
    break
  else:
    c+=1

if x!=0:
  c-=1


print(c)

Submission status: Accepted

Solution code:
# AGC 027: A – Candy Distribution Again
n, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

a.sort()

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

if x == a[n - 1]:
    answer += 1

print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np


def main(n, x, a):
  cnt = 0
  for j, i in enumerate(a):
    x -= i
    if x < 0:
      break
    elif j == n-1 and x > 0:
      break
    cnt += 1
  return cnt

n, x = map(int, readline().split())
a = np.sort(np.array(readline().split(), np.int64))
print(main(n, x, a))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
a = input().split()
N = int(a[0])
budget = int(a[1])
b = [int(s) for s in input().split()]
c = sorted(b)
d = int(0)
for i in range(N-1):
  if budget >= c[i]:
    budget = budget - c[i]
    d = d + 1
  else:
    break

if c[N-1] == budget:
    d = d + 1

print(d)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

Submission status: Accepted

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

a.sort()

if sum(a) < x:
    print(N - 1)

elif sum(a) > x:
    ans = 0
    ans_ = 0
    for a in a:
        ans_ += a
        if ans_ > x:
            break
        ans += 1
    print(ans)

elif sum(a) == x:
    print(N)

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
a=sorted([int(i)for i in input().split()])
res=0
if sum(a)==x:
    res=n
else:
    for i in range(n):
        if sum(a[:i])<=x:res=i
print(res)

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
a=sorted([int(i)for i in input().split()])
res=0
if sum(a)==x:
    res=n
else:
    for i in range(n):
        if sum(a[:i])<=x:res=i
print(max(0,res))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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
# print(x)
print(min(ans,n-1 if x>0 else n))

Submission status: Accepted

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

if a_sum== x:
    print(n)
else:
    print(n-1)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
if sum(a)==x:
    print(N)
else:
    a.sort()
    s=0
    i=0
    while True:
       s+=a[i]
       if i==N-1 and s!=x:
           print(N-1)
           break
       if s>x:
           print(i)
           break
       i+=1
       if i>=N:
           print(N)
           break

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#
# agc027 a
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 70
20 30 10"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3 10
20 30 10"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """4 1111
1 10 100 1000"""
        output = """4"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """2 10
20 20"""
        output = """0"""
        self.assertIO(input, output)


def resolve():
    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 -= a[i]
            ans += 1
    if a[-1] == x:
        ans += 1
    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
L = list(map(int, input().split()))
l = sorted(L)
c = 0
if sum(L) < x:
  print(len(l)-1)
else:
  for i in range(N):
    if x < l[i]:
      break
    x = x - l[i]
    c += 1
    
  print(c)

Submission status: Accepted

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

a.sort()
ans = 0

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

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

Submission status: Accepted

Solution code:
def candy(arr, n, x):
	if sum(arr) == x:
		return n
	arr.sort()
	best = 0
	j = 0
	while(j < n):
		temp = x
		c = 0
		for i in range(j, n-1):
			if arr[i] < temp:
				c += 1
				temp -= arr[i]
			elif arr[i] == temp:
				c += 1
				break
			if i == n - 2:
				if temp == arr[n-1]:
					c += 1
		best = max(best, c)
		j += 1
	return best
n, x = map(int, input().split())
arr = list(map(int, input().split()))
print(candy(arr, n, x))

Submission status: Accepted

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

	a.sort()
	a_sum = 0
	ans = 0

	for i in range(N):
		a_sum += a[i]
		ans += 1

		if a_sum > x:
			ans -= 1
			break

		if i == N - 1 and a_sum < x:
			ans -= 1
			break

	print(ans)


  
if __name__ == "__main__":
  	main()

Submission status: Accepted

Solution code:
N,x = map(int,input().split())
AAA = map(int,input().split())
AA = list(AAA)
AA.sort()
total = 0
count =0
for i in AA:
  total += i
if total == x:
  ans = N
elif total < x:
  ans = N-1
else:
  for i in AA:
    if x >= i:
      x -= i
      count +=1
  ans = count
print(ans)

Submission status: Accepted

Solution code:
import sys
input = lambda :sys.stdin.readline().rstrip()

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

if x > sum(A):
  cnt = -1
else:
  cnt = 0
  
for i in range(N):
    if x - A[i] >= 0:
        cnt += 1
        x -= A[i]
    if x <= 0:
        break
    #print(cnt, x)

print(cnt)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

a_cs = [0] * (n + 1)
for i in range(n):
    a_cs[i + 1] = a_cs[i] + a[i]

idx = bisect_left(a_cs, x)
if idx == n + 1:
    ans = n - 1
elif a_cs[idx] > x:
    ans = idx - 1
else:
    ans = idx
print(ans)

Submission status: Accepted

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

a.sort()

A = sum(a)
if x > A:
  print(N-1)

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

Submission status: Accepted

Solution code:
import math
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 and x >= a[i] or i == N - 1 and x == a[i]:
        ans += 1
        x -= a[i]
print(ans)

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
L=list(map(int,input().split()))
L=sorted(L)
ans=0
if sum(L)<b:
  print(a-1)
elif sum(L)==b:
  print(a)
else:
  for i in range(a):
    ans+=L[i]
    if ans>b:
      print(i)
      exit()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,x = input().split()
A = input().split()
a = []
for i in range(int(N)):
  a.append(int(A[i]))
  
a.sort()
X = int(x)
 
idx = 0
while X>0 and idx<int(N):
  X = X-a[idx]
  idx+=1

if X==0:
  idx+=1
  
print(idx-1)