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()))
answer = 0
while x > 0  :
    A = sorted(A)
    if x < A[0] :
        break
    x = x - A[0]
    answer += 1
    A.pop(0)
    if len(A) == 0 :
        if x != 0 :
            answer -= 1
        break
print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

a.sort()
if a[0] > x:
  print(0)
  exit()

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

# 端数
if x != 0 and count == N:
    count -= 1

print(count)

Submission status: Accepted

Solution code:
import math


def main():
    N, x = [int(a) for a in input().split()]
    ai = sorted([int(a) for a in input().split()])

    bi = []
    t = 0
    for a in ai:
        t += a
        bi.append(t)

    def solve():
        cc = 0
        for i in range(N):
            if bi[i] < x:
                cc += 1
                continue
            if bi[i] == x:
                return cc + 1
            if bi[i] > x:
                return cc
        return cc - 1

    cc = solve()
    print(cc)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

# なんこか入力
n,x = map(int, input().split())

# 空白区切りの数列をリストに代入
a = [int(i) for i in input().split()]

a=sorted(a)

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

Submission status: Accepted

Solution code:
def bubble(a):
    for i in range(len(a)-1):
        for j in range(len(a)-1-i):
            if a[j] > a[j+1]:
                tmp=a[j]
                a[j]=a[j+1]
                a[j+1]=tmp

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

a = list(map(int,input().split()))
bubble(a)
ans = 0

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

Submission status: Accepted

Solution code:


N,x = [int(x) for x in input().split()]

al = [int(x) for x in input().split()]


al.sort()

count=0
acc = 0
for ai in al:
    acc += ai
    if acc > x:
        break
    count+=1
if acc < x:
    count -= 1

print(count)

Submission status: Accepted

Solution code:
N,x = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
i = 0
tmp = 0
while True:
    if i == len(A):
        if  x - tmp == 0:
            print(i)
            exit()
        else:
            print(i - 1)
            exit()
    else:
        tmp += A[i]
        if tmp > x:
            print(i)
            exit()
        else:
            i += 1

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 range(N):
    if a[i] <= x and i != (N-1):
        count += 1
        x -= a[i]
    elif a[i] == x and i == (N-1):
        count += 1

print(count)

Submission status: Accepted

Solution code:
from sys import stdin

N, x = [int(a) for a in stdin.readline().rstrip().split()]
a = [int(b) for b in stdin.readline().rstrip().split()]
a.sort()

ans = 0
for i in range(len(a)):
    if i < len(a) - 1 and x >= a[i]:
        ans += 1
        x -= a[i]
    elif i == len(a) - 1 and x == a[i]:
        ans += 1
        break
    elif i == len(a) - 1 and x > a[i]:
        pass
    else:
        break

print(ans)

Submission status: Accepted

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

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

c_list.sort()


i = 0
for _ in range(len(c_list)):
    if x - c_list[i] < 0:
        print(i)
        exit()
    x -= c_list[i]
    i += 1

if x == 0:
    print(len(c_list))
else:
    print(len(c_list) - 1)

Submission status: Accepted

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

As.sort()

ans = 0
for A in As:
    if x > A:
        x -= A
        ans += 1
    elif x == A:
        ans += 1
        break
    else:
        break
else:
    ans -= 1

print(ans)

Submission status: Accepted

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

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

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

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(len(A)):
    x=x-A[i]
    if x>=0 and i!=len(A)-1:
        ans+=1
    elif x==0 and i==len(A)-1:
        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()
k = 0; ans = 0
while A[k] <= x:
    ans += 1
    x -= A[k]
    if k+1 == N:
        A[k] = x+1
        if x > 0:
            ans -= 1
    else:
        k += 1
print(ans)

Submission status: Accepted

Solution code:
DT = input()
data = DT.split()

N = int(data[0])
x = int(data[1])

DT = input()
a = DT.split()
for lop in range(len(a)):
    a[lop] = int(a[lop])
a = sorted(a)

cnt = 0
for lop in range(len(a)):
    if x < 0:
        break
    x -= a[lop]
    cnt += 1

if not(x == 0):
    cnt -= 1

print(cnt)

Submission status: Accepted

Solution code:
import numpy as np

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

cum = np.cumsum(a)

if x == cum[-1]:
    print(n)
elif x > cum[-1]:
    print(n-1)
else:
    temp = cum <= x
    print(sum(temp))

Submission status: Accepted

Solution code:
N, K = [int(i) for i in input().split(' ')]
As = [int(i) for i in input().split(' ')]

r = 0
f = 1
for i in sorted(As):
    K -= i
    if K < 0:
        f = 0
        break
    r += 1

if f == 1 and K != 0:
    print(r-1)
else:
    print(r)

Submission status: Accepted

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

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

Submission status: Accepted

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

for ai in a[:-1]:
    if x >= ai:
        x -= ai
        if x >= 0:
            ans += 1
    else:
        break

if x == a[-1]:
    ans += 1
    
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys

ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: [int(x) for x in ns().split()]
nall = lambda: [int(x) for x in sys.stdin.readlines()]

def main():
    n, x = na()
    aa = na()

    aa.sort()
    #print(aa)

    c = 0
    for a in aa:
        x -= a
        if x >= 0:
            c += 1
            
    if x > 0:
        c -= 1
    print(c)


main()

Submission status: Accepted

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

cum = 0
res = 0
for i, ch in enumerate(cs):
  cum += ch
  if cum > c: break
  res += 1

print(res if cum >= c else res - 1)

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

Submission status: Accepted

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

cnt = 0
for i in range(n):
    min_a = min(a)
    a.remove(min_a)
    if x < min_a:
        break
    x -= min_a
    cnt += 1

if cnt == n and x != 0:
    cnt -= 1

print(cnt)

Submission status: Accepted

Solution code:

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

if sum(ai)<x:
    print(n-1)
elif sum(ai)==x:
    print(n)
else:
    divi = 0
    for k in range(n):
        if divi + ai[k] > x:
            print(k)
            break
        divi += ai[k]

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

print(ans)

Submission status: Accepted

Solution code:
list1 = list(map(int, input().split()))
list2 = list(map(int, input().split()))
n = list1[0]
x = list1[1]
count = 0

for i in range(n):
    if i == n - 1:
        if x == min(list2):
            count = count + 1
        else:
            break
    elif x >= min(list2):
        x = x - min(list2)
        list2.remove(min(list2))
        count = count + 1
    else:
        break
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,X = map(int,input().split())
src = list(map(int,input().split()))
src.sort()

x = 0
ans = 0
for a in src:
    if x+a > X: break
    ans += 1
    x += a
if x != X and ans == N:
    ans -= 1
print(ans)

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(N, x, A):
    A = sorted(A)
    count = 0
    for i, a in enumerate(A):
        x -= a
        if i == len(A) - 1:
            if x == 0:
                count += 1
        elif x >= 0:
            count += 1
        else:
            break
    return count

if __name__ == "__main__":
    l = input()
    N, x = int(l.split()[0]),int(l.split()[1])
    A = [int(c) for c in input().split()]
    print(solve(N, x, A))

Submission status: Accepted

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

ans = 0

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

if x > 0:
    ans -= 1

print(ans)

Submission status: Accepted

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

if min(a) > x:
    print(0)
    sys.exit()

if sum(a) == x:
    print(n)
    sys.exit()

a.sort()
l = 0
for i,s in enumerate(a):
  l += s
  if l > x:
    print(i)
    sys.exit()
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):
    x -= A[i]
    if x<0:
        ans = i
        break
else:
    if x!=0:
        print(N-1)
    else:
        print(N)
    exit()
print(ans)

Submission status: Accepted

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

cnt = 0
finished = True

for i in l:
    if i <= x:
        x -= i
        cnt += 1
    else:
        finished = False
        break

if finished and x:
    cnt -= 1

print(cnt)

Submission status: Accepted

Solution code:
import sys
N,x=map(int,input().split())
A=[int(i) for i in input().split()]
A.sort()
y=x
ans=0
if A[0]>y:
    print(0)
    sys.exit()
for i in range(N):
    if y<A[i]:
        print(ans)
        sys.exit()
    ans+=1
    y-=A[i]
    #print(y)
if y!=0:
    ans-=1
print(ans)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

sum_a = sum(a)
if sum_a < x:
    print(N-1)
    exit()
elif sum_a == x:
    print(N)
    exit()

rest = sum_a - x
a.sort()
for i in range (N-1, -1, -1):
    rest -= a[i]
    if rest <= 0:
        print(i)
        exit()
print(0)

Submission status: Accepted

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

Submission status: Accepted

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

N, x = inpl()
a = inpl()
a = sorted(a)
ans = 0
for ai in a:
    if x>=ai:
        x -= ai
        ans += 1
    else:
        break
else:
    if x!=0:
        ans -= 1
print(ans)

Submission status: Accepted

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

sAs = sorted(As)

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

if all([n == 0 for n in sAs]) and x != 0:
    c -= 1

print(c)

Submission status: Accepted

Solution code:
N, num = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
sum = 0
for count, i in enumerate(a):
    sum+= i
    if sum > num:
        print(count)
        exit()
if sum == num:
    print(N)
else:
    print(N-1)

Submission status: Accepted

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

a.sort()
count = 0
cur = 0
for i in range(N):
    cur += a[i]
    if x < cur:
        break
    elif i == N - 1:
        if cur == x:
            count += 1
    else:
        count += 1

print(count)

Submission status: Accepted

Solution code:
N,x = map(int, input().split())
lis = [int(i) for i in input().split()]
lis.sort()
s = 0
ans = 0
for nums in lis:
  if x >= nums:
    x += -nums
    ans += 1
if ans == N and x != 0:
  ans = ans-1
print(ans)

Submission status: Accepted

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

v,c=0,0
for (i,j) in enumerate(a):
  if x>=j:
    x-=j
    c+=1
    if i==N-1 and x>0:
      c-=1
print(c)

Submission status: Accepted

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

a_list.sort()
sum_num = 0
for i in range(N):
    item = a_list[i]
    if x >= item:
        if i != N-1:
            sum_num += 1
            x -= item
        elif x == item:
            sum_num += 1
            x -= item
    else:
       break
print(sum_num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
n -= 1
a = list(map(int, input().split()))
a.sort()
ans = 0
for i, ai in enumerate(a):
    if x < ai:
        break
    elif i == n and  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()
#print(A)
result=0
for i in range(len(A)):
    #print(x)
    if i==len(A)-1:
         if A[i]==x:
             result+=1
    elif A[i]<=x:
        x-=A[i]
        result+=1

    else:
        break
print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
USE_STDIO = False

if not USE_STDIO:
    try: import mypc
    except: pass

def main():
    n, x = map(int, input().split(' '))
    A = list(map(int, input().split(' ')))
    A.sort()
    ans = 0
    for i, a in enumerate(A):
        if a > x: break
        x -= a
        if x == 0 or i != len(A) - 1:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

def f():
    As = sorted(A)
    s = 0
    for i,a in enumerate(As):
        s += a
        if x < s:
            return i
        if x == s:
            return i + 1
    return N - 1
print(f())

Submission status: Accepted

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

A.sort()

ans = 0

fl = True
for i in range(N):
  if A[i] <= X:
    ans += 1
    X -= A[i]
  else:
    fl = False
    break
    
if fl 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()

R = 0
F = False

for a in A[:-1]:
    if a <= x:
        R += 1
        x -= a
    else:
        break
        F = True

if A[-1] == x or (A[-1] > x and F == True):
    R += 1

print(R)

Submission status: Accepted

Solution code:
N, x= map(int, input().split())
A = [int(x) for x in input().split()]
A.sort()
cnt = 0
for i, a in enumerate(A):
  if i < N - 1:
    cnt += 1 if x >= a else 0
    x -= min(x, a)
  else:
    cnt += 1 if x == a else 0
print(cnt)

Submission status: Accepted

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

def solve(n, x, bs):
    cs = sorted(bs)
    res = 0
    for c in cs:
        if c <= x:
            x -= c
            res += 1
        else:
            break
    if x > 0 and res == n:
        res -= 1
    return res


def main():
    n, x = (int(z) for z in input().split())
    bs = [int(b) for b in input().split()]
    res = solve(n, x, bs)
    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

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

    a = sorted(a)
    ans = 0
    tmp = 0
    for i in a:
        tmp += i
        if tmp <= x:
            ans+=1

    if n == ans:
        if sum(a) != x:
            ans-=1

    print(ans)




if __name__ == "__main__":
        main()

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
listA = list(map(int, input().split()))
listSum =0
for a in listA:
    listSum+=a

if listSum == x:
    print(n)
elif listSum < x:
    print(n-1)
else:
    listA.sort()
    index =0
    sum =0
    while sum < x+1:
        sum += listA[index]
        index+=1
    print(index-1)

Submission status: Accepted

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

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

Submission status: Accepted

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

a.sort()

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

if(x > 0): ans -= 1

print(ans)

Submission status: Accepted

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


def main():
    N, x = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    ANS = 0
    for a_i in a:
        if a_i <= x:
            ANS += 1
            x -= a_i
        else:
            print(ANS)
            return
    if x != 0:
        ANS -= 1
    print(ANS)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

sum_a = 0
for i in range(n):
    sum_a += a[i]

if sum_a == x:
    print(n)
elif sum_a < x:
    print(n - 1)
else:
    a.sort()
    count = 0
    while True:
        if x >= a[count]:
            x -= a[count]
            count += 1
        else:
            break
    print(count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

in_strings = lambda: stdin.readline()[:-1] # s = in_strings()
in_int = lambda: int(stdin.readline()) # N = in_int()
in_intlist = lambda: list(map(int, stdin.readline().split())) # List = in_intlist()

N, X = in_intlist()
a_list = in_intlist()

a_list.sort()

flag = 1
dist = 0
count = 0
for i in range(N):
    dist += a_list[i]
    if dist <= X:
        count += 1
    else:
        flag = 0
        break
if flag and (dist < X):
    count -= 1

print(count)

Submission status: Accepted

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

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

b.sort()

su = 0

for i in range(a[0]):
	if i == a[0]-1 and (a[1] > b[i] or a[1] < b[i]):break
	elif a[1] >= b[i]:
		su += 1
		a[1] -= b[i]
	else:
		break
print(su)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
if sum(a) == x:
    ans = len(a)
elif sum(a) < x:
    ans = len(a) - 1
else:
    a.sort()
    for v in a:
        if v <= x:
            x -= v
            ans += 1
        else:
            break

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
try: from typing import Any, Union, List, Tuple, Dict
except ImportError: pass
sys.setrecursionlimit(10**6)
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)


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


a.sort()


i = 0
s = 0
while (i<N) and (s <= x):
    s += a[i]
    i += 1


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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
n,x = list(map(int,input().split()))	
a = list(map(int,input().split()))
a.sort()

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

print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
if sum(a)<x:
    a.sort(reverse=True)
else:
    a.sort()
c=0
for t in a:
    x-=t
    if x<0:break
    c+=1
if x>0:
    print(c-1)
else:
    print(c)

Submission status: Accepted

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[n,x]=i2()
a=i2()
a.sort()
b=0
for i in range(n):
 x-=a[i]
 if x<0:
    break
 b+=1
if x>0 and b==n:
   print(b-1)
else:
   print(b)

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

Submission status: Accepted

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

Submission status: Accepted

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

n,x = ri()
a = sorted(ri())
ans = 0
c = 0
for i in a:
    c += i
    if c>x:
        break
    ans += 1
if c<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):
    x -= a[i]
    if x < 0:
        break
    ans += 1
if x > 0:
    ans -= 1
print(ans)

Submission status: Accepted

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

if x > sum(a):
    ans = N-1
else:
    for b in a:
        if x >= b:
            x -= b
            ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

a.sort()

ans = 0
for ai in a:
    if ai <= amount:
        amount -= ai
        ans += 1

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
I = lambda: [int(i) for i in input().split()]
n,k=I()
a=I()
a.sort()
s=0
for i in a:
  k-=i
  if k>=0:
    s+=1
  if k<=0:
    break
else:
  s-=1
print(s)

Submission status: Accepted

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

ans = 0
acm = 0
for i in ass:
    acm += i
    if x >= acm:
        ans +=1

if acm < x:
    ans -= 1

print(ans)

Submission status: Accepted

Solution code:
import sys

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

S=[None]*N
S[0]=A[0]

if A[0]>x:
    print(0)
    sys.exit()

for i in range(1,N):
    S[i]=S[i-1]+A[i]
    if S[i]>x:
        break

if S[i]==x:
    print(N)
else:
    print(i)

Submission status: Accepted

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

a.sort()

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

Submission status: Accepted

Solution code:
INF = 999999999999999999L
EPS = 1e-12

def read():
    return raw_input().strip()

def read_ints():
    return map(int,read().split())

n,x = read_ints()
a = read_ints()
a.sort()
ans = 0
for i in range(len(a)):
    if i == len(a)-1 and x == a[i]:
        ans += 1 
    elif i != len(a)-1 and a[i] <= x:
        ans += 1 
        x -= a[i] 
print ans

Submission status: Accepted

Solution code:
def ii():
    return int(input())
def mi():
    return map(int, input().split())
def li():
    return list(mi())

N, x = mi()
a = li()
a.sort()
c = 0
for ai in a:
    if x < ai:
        break
    x -= ai
    c += 1
if c == N and x > 0:
    c -= 1
print(c)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from itertools import accumulate
from bisect import bisect_right

n,x = li()
a = list(li())

a.sort()
a_cum = list(accumulate(a))


if x == a_cum[-1]:
    print(n)

elif x > a_cum[-1]:
    print(n-1)
    
else:
    ans = bisect_right(a_cum, x)
    print(ans)

Submission status: Accepted

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

if ans == n and b[-1] != x:
	ans -= 1
print(ans)