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: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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
         break
      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: Wrong Answer

Solution code:

def myAnswer(N:int,x:int,A:list) -> int:
   if(sum(A)==x): return N
   A.sort()
   counter = 0
   for n,a in enumerate(A):
      if(a <= x):
         x -= a
         counter += 1
      else:
         break
   if(x != 0 and counter != 0 ):
      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: Wrong Answer

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans = 0
X = x
for A in a:
    if x < A:
        break
    x -= A
    ans += 1
if sum(a)!=X:
    ans = ans - 1
print(ans)

Submission status: Wrong Answer

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:
        print(i)
        break
else:print(n)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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 = LI()
ans = 0
a.sort()
for y in a:
    if x>=y:
        x -= y
        ans += 1
    else:
        break
print(ans)

Submission status: Wrong Answer

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
print(str(count))

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
l1=list(map(int,input().split()))
l1.sort()
ans=0
while len(l1)>0:
    t1=l1.pop(0)
    if x>=t1:
        x-=t1
        ans+=1
if ans>0 and x>0:
    ans-=1
print (ans)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
l1=list(map(int,input().split()))
l1.sort()
ans=0
while len(l1)>0:
    t1=l1.pop(0)
    if x>=t1:
        x-=t1
        ans+=1
print (ans)

Submission status: Wrong Answer

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()
d=[]
now=0
for i in l:
    now+=i;d.append(now)
from bisect import bisect_left as bl,bisect_right as br

print(bl(d,x))

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
l=sorted(list(map(int,input().split())))
if sum(l)>x:print(n-1);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(bl(d,x))

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
l=sorted(list(map(int,input().split())))
d=[]
now=0
for i in l:
    now+=i;d.append(now)
from bisect import bisect_left as bl,bisect_right as br

print(max(0,br(d,x)-1+(sum(l)==x)))

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
l=sorted(list(map(int,input().split())))
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)-1+(sum(l)==x))

Submission status: Wrong Answer

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:
    count -= 1
print(max(count,0))

Submission status: Wrong Answer

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
        print(X)
    else:
        break
if X > 0:
    count -= 1
print(max(count,0))

Submission status: Wrong Answer

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()
total = 0
ans = 0
for i in a:
    if total + i <= x:
        ans += 1
        total += i
if total != x:
    ans -= 1
print(max(ans, 0))

Submission status: Wrong Answer

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: Wrong Answer

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 if S[l] == x else max(0, l-1))

Submission status: Wrong Answer

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 - (S[l] != x))

Submission status: Wrong Answer

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 - (S != x))

Submission status: Wrong Answer

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

print(ans-1)

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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:
    pass

if x != 0 and cnt != 0:
  cnt -= 1
else:
  pass

print(cnt)

Submission status: Wrong Answer

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 x != 0 and cnt != 0:
  cnt -= 1
else:
  pass

print(cnt)

Submission status: Wrong Answer

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

okashi = 0
ans = 0
while okashi < x:
  for i in range(N):
    okashi += sorted(A)[i]
  ans +=1

print(ans)

Submission status: Wrong Answer

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(n)
        exit()
print(n)

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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:
    total = N - 1
        
print(total)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

L = sorted(L)

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

Submission status: Wrong Answer

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

L = sorted(L)

total = 0
i = 0
while M > 0 and i < N:
    M -= int(L[0])
    L.pop(0)
    total += 1
    i += 1

print(total)

Submission status: Wrong Answer

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
    else:
      break
print(count)

Submission status: Wrong Answer

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
    else:
      break
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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]
if count > 0 and x > 0:
    count -= 1

print(count)

Submission status: Wrong Answer

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 x > 0:
  ans -= 1
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
s=0
while s<n:
  if m>=a[s]:
    m-=a[s]
    s+=1
  else:break
if m>0:#最後余った時
  s-=1
print(s)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
s=0
while s<n-1:
  if m>=a[s]:
    m-=a[s]
    s+=1
  else:break
print(s)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
s=0
while s<n:
  if m>=a[s]:
    m-=a[s]
    s+=1
  else:break
print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

sum = 0
ans = 0
a.sort()

for i in range(n):
    sum += a[i]
    if sum <= k:
        ans += 1
    else:
        break

print(ans)

Submission status: Wrong Answer

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
print(max(ans,0))

Submission status: Wrong Answer

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 x != 0:
    ans -= 1
print(max(ans,0))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a.sort()
i = 0

while i < n:
    x -= a[i]
    if (x < 0):
        break
    i += 1

print(i)

Submission status: Wrong Answer

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

a.sort()
i = 0

while i < n:
    x -= a[i]
    if (x < 0):
        break
    i += 1

if (x != 0):
    i -= 1

print(i)

Submission status: Wrong Answer

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]
    if x>=a:
        person_num += 1
        x = x - a
    else:
        break

# output
print(person_num)

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
a = sorted(map(int,input().split()),reverse=False)
ans = 0
for i in a:
    if x - i >= 0:
        x -= i
        ans += 1

if x > 0 and ans > 0:
    ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
a = sorted(map(int,input().split()),reverse=False)
ans = 0
for i in a:
    if x - i >= 0:
        x -= i
        ans += 1

if x > 0:
    ans -= 1

print(ans)

Submission status: Wrong Answer

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

a.sort(reverse=True)

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: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_left


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_left(accumulate_target, cookies) + 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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: Wrong Answer

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: Wrong Answer

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:
    cnt_candy += item
    if cnt_candy < x:
        cnt_children += 1

if cnt_candy != x:
    cnt_children -= 1

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

Submission status: Wrong Answer

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 == 3:
    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: Wrong Answer

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

Submission status: Wrong Answer

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]

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

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

Submission status: Wrong Answer

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]
  ans = i+1
  if total > x:
    ans = i
    break
  
  
print(ans)

Submission status: Wrong Answer

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
  ans = i+1
  
print(ans)

Submission status: Wrong Answer

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


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

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

Submission status: Wrong Answer

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 :
        break
if x != 0 :
    ans -= 1
print(max(0, ans))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=a[0]
y=a[1]
b.sort()
i=0
k=0
while i ==0:
	t=b[0]
	if y>=t:
		k=k+1
		del b[0]
	else:
		i=1
	if x==k:
		i=1
print(k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

cnt = 0
if x >= sum(A):
  cnt -= 1
  
for a in A:
  if x >= a:
    x -= a
    cnt += 1
  else:
    break
      
print(cnt)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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