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

result = 0

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

Submission status: Accepted

Solution code:
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

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

Submission status: Accepted

Solution code:

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

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

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
mo = 10**9+7

def main():
	n,x = MI()
	a = LI()
	a.sort()
	ans=0
	for i,aa in enumerate(a,1):
		if(x>=aa and i!=n):
			x-=aa
			ans+=1
		if(i==n and x==aa):
			ans+=1
	print(ans)

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
def myAnswer(N:int,x:int,A:list) -> int:
   if(sum(A)==x): return N
   A.sort()
   counter = 0
   hantei = True
   for n,a in enumerate(A):
      if(a > x):
         hantei = False
         break
      elif(a == x):
         counter += 1
         return counter
      elif(a < x):
         x -= a
         counter += 1

   if(x != 0 and counter != 0 and hantei ):
      counter -=1
   return counter

def modelAnswer():
   tmp=1
def main():
   N,x = map(int,input().split())
   A = list(map(int,input().split()))
   print(myAnswer(N,x,A[:]))


if __name__ == '__main__':
   main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n, x = map(int,input().split())
a = [int(i) for i in input().split()] 

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N, x = map(int, input().split())
a = list(map(int, input().split()))
a = np.sort(np.array(a))
cumul = np.cumsum(a)
sign = np.sign(cumul - x)

if np.all(sign == -1):
    print(N - 1)
else:
    print(np.sum(sign <= 0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
sort_a = sorted(a)
count = 0
for y in range(len(sort_a)):
    if y != len(sort_a) - 1:
        if sort_a[y] <= x:
            x -= sort_a[y]
            count += 1
        else:
            break
    else:
        if sort_a[y] == x:
            count += 1

print(count)

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,numpy,string
def I(): return int(input())
def S(): return input()
def LI(): return list(map(int,input().split()))
def LS(): return list(input().split())
##################################################
N,x = LI()
a = sorted(LI())
ans = 0
if a[0]>x:
    pass
else:
    for i in range(N):
        if i!=N-1 and a[i+1]<=x:
            x -= a[i]
            ans += 1
        elif i!=N-1 and a[i+1]>x:
            if a[i]==x:
                ans += 1
                break
        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 = sorted(a)
count = 0
while(x >= 0):
  if(count == N):
    break
  tmp = a.pop(0)
  if(x >= tmp):
    x = x - tmp
    count += 1
  else:
    break
if(count == N and x != 0):
  count -= 1
print(str(count))

Submission status: Accepted

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

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

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

ans = 0
for i in range(N):
    if sum(A[:i]) <= x:
        ans = i
print(ans)

Submission status: Accepted

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

a.sort()
ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
c = 0
a.sort()
for i in a:
  c += 1
  x -= i
  if x < 0:
    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()
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())
l=sorted(list(map(int,input().split())))
if sum(l)<=x:print(n-int(sum(l)!=x));exit()
if l[0]>x:print(0);exit()
d=[]
now=0
for i in l:
    now+=i;d.append(now)
from bisect import bisect_left as bl,bisect_right as br

print(br(d,x))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

n, x = map(int, stdin.readline().rstrip().split())
a = list(map(int, stdin.readline().rstrip().split()))

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt
from functools import lru_cache, reduce
INF = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# ここから書き始める
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
# print("a =", a)
b = [0] * n
for i in range(n - 1):
    if x == 0:
        continue
    b[i] = min(x, a[i])
    x -= min(x, a[i])
b[-1] = x
ans = 0
for i in range(n):
    if a[i] == b[i]:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
A = sorted(list(map(int, input().split())))
S = [0]
for i in range(N):
    S.append(S[i] + A[i])
# print(S)
l = -1
r = N+1
while r - l > 1:
    m = l + (r-l)//2
    if S[m] > x:
        r = m
    else:
        l = m
print(l - (l == N and S[l] < x))

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
A = sorted(list(map(int, input().split())))
S = 0
ans = 0
for a in A:
    if S + a > x:
        break
    else:
        S += a
        ans += 1

print(ans - (ans == N and S != x))

Submission status: Accepted

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

flag = 0

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

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:
    x = 0
    break

if not x == 0:
  cnt -= 1

print(cnt)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, x = MAP()
a = LIST()

a.sort()

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

Submission status: Accepted

Solution code:
# AGC 027 A - Candy Distribution Again
n, x = map(int, input().split())
a = list(map(int, input().split()))

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

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

Submission status: Accepted

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

for i in a:
    wa += i
    cnt += 1
    if wa > x:
        print(cnt - 1)
        exit()
        
    elif wa == x:
        print(cnt)
        exit()
print(cnt - 1)

Submission status: Accepted

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

Submission status: Accepted

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

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):
    if x > A[i] and i != n - 1:
        x = x - A[i]
        ans = ans + 1
    elif x == A[i]:
        ans = ans + 1
        break
    else:
        break

print(ans)

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
n,x = iim()
A = sorted(iil())
count = 0
for i in A:
    x -= i
    count += 1
    if x < 0:
        print(count-1)
        exit()
    elif x == 0:
        print(count)
        exit()
print(count-1)

Submission status: Accepted

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

L = sorted(L)

total = 0
for i in range(N):
    if M - int(L[0]) >= 0:
        M -= int(L[0])
        total += 1
        L.pop(0)

if total == N and not M == 0:
    total = N - 1
        
print(total)

Submission status: Accepted

Solution code:
n,x = map(int,input().split())
line = sorted(list(map(int,input().split())))
count = 0
if sum(line) < x:
  count = n - 1
elif sum(line) == x:
  count = n
else:
  for i in range(n):
    left = x - line[i]
    if left >= 0:
      count += 1
      x = left
    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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

# print(N, x)
# print(A)

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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


A = sorted(A)
t = 0
num = 0
if sum(A) < x:
    print(n - 1)
else:
    for i in A:
        if t + i <= x:
            t += i
            num += 1
        else:
            break
    print(num)

Submission status: Accepted

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N,x = imn()
a = sorted(iln())

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

Submission status: Accepted

Solution code:
#template
def inputlist(): return [int(j) for j in input().split()]
from collections import Counter
#template
#issueから始める
N,x = inputlist()
a = inputlist()
a.sort()
count=0
for i in range(N):
    x -=a[i]
    if x < 0:
        print(count)
        exit()
    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()
cnt = 0
if x > sum(A):
    print(n-1)
else:
    for i in range(n):
        if (x - A[i]) >= 0:
            x -= A[i]
            cnt += 1
        else:
            break
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

Solution code:
def main():
    N, x = map(int, input().split())
    a = sorted(map(int, input().split()))
    cnt = 0
    for i in range(N):
      if a[i] <= x:
        cnt += 1
        x -= a[i]
      else:
        break
    if cnt == N and x > 0:
      cnt -= 1
    print(cnt)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

print(i)

Submission status: Accepted

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

Submission status: Accepted

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


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


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, x, a)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# Problem A - Candy Distribution Again

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

# initialization
a_list = sorted(a_list)
person_num = 0

# count process
for i in range(len(a_list)):
    a = a_list[i]
    x = x - a
    if x >= 0:
        person_num += 1

# output
if x>0:
    print(person_num - 1)
else:
    print(person_num)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#codng utf-8
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
    else:
        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.sort()

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

Submission status: Accepted

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

if x > sum(a):
    print(n-1)
else:
    a.sort()
    while(x > 0):
        x -= a[i]
        if x >= 0:
            i += 1
    print(i)

Submission status: Accepted

Solution code:
from itertools import accumulate
from bisect import bisect_right


def main():
    children, cookies = map(int, input().split())
    target = sorted(list(map(int, input().split())))
    sum_target = sum(target)
    if sum_target < cookies:
        print(children - 1)
    elif cookies < target[0]:
        print(0)
    else:
        accumulate_target = list(accumulate(target))
        print(bisect_right(accumulate_target, cookies))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

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

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

a.sort()

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

# if x > 0 and cnt_children == n:
#     cnt_children -= 1

# print("{}".format(cnt_children))

# cnt_candy = 0
# cnt_children = 0
# for item in a:
#     if cnt_candy < x:
#         cnt_candy += item
#         cnt_children += 1

# if cnt_candy != x:
#     cnt_children -= 1

# print("{}".format(cnt_children))

if x == sum(a):
    print("{}".format(n))
else:    
    cnt_candy = 0
    cnt_children = 0

    for index, item in enumerate(a):
        cnt_candy += item
        if x >= cnt_candy:
            cnt_children = index + 1

    if x > sum(a):
        print("{}".format(n-1))
    else:
        print("{}".format(cnt_children))

Submission status: Accepted

Solution code:
import sys

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

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

a.sort()

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

if x > 0 and cnt_children == n:
    cnt_children -= 1

print("{}".format(cnt_children))

# cnt_candy = 0
# cnt_children = 0
# for item in a:
#     if cnt_candy < x:
#         cnt_candy += item
#         cnt_children += 1

# if cnt_candy != x:
#     cnt_children -= 1

# print("{}".format(cnt_children))

Submission status: Accepted

Solution code:
import sys

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

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

a.sort()

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

# if x > 0 and cnt_children != 0:
#     cnt_children -= 1

# print("{}".format(cnt_children))

cnt_candy = 0
cnt_children = 0
for item in a:
    if cnt_candy < x:
        cnt_candy += item
        cnt_children += 1

if cnt_candy != x:
    cnt_children -= 1

print("{}".format(cnt_children))

Submission status: Accepted

Solution code:
n,x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
cnt = 0
while a[cnt] <= x:
    x = x - a[cnt]
    cnt += 1
    if cnt >= len(a):
        break
if x > 0 and len(a) == cnt:
    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
while x>0:
    #print(x)
    if x>=A[cnt]:
        x-=A[cnt]
        cnt+=1
    else:
        break
    if len(A)==cnt:
        if x>0:
            cnt-=1
        break
print(cnt)

Submission status: Accepted

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


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

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

Submission status: Accepted

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

from itertools import accumulate

A = tuple(accumulate(A))

ans = N - 1
for i,a in enumerate(A):
    if x > a:
        pass
    elif x == a:
        ans = i + 1
        break
    else:
        ans = i
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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