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

Submission status: Accepted

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

sort_a = sorted(a)
count = 0
if x > sum(a):
  count-=1
for i in sort_a:
  if x >= i:
    count+=1
    x-=i
  else:
    print(count)
    exit()
print(count)

Submission status: Accepted

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

    A.sort()

    if sum(A) == x:
        return n

    for i in range(0, n):
        x -= A[i]
        if x < 0:
            break
    ans = i
    return ans


print(main())

Submission status: Accepted

Solution code:
def main():
    N, x = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    if sum(a) == x:
        print(N)
        return
    for i in range(N):
        x -= a[i]
        if x < 0:
            break
    ans = i
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

if X - sum(lists) == 0:
    print(len(lists))
    exit()

count = 0
for num in sorted(lists):
    X -= num
    if X >= 0:
        count += 1

if X < 0:
    print(count)
else:
    print(count - 1)

Submission status: Accepted

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

# a_listの総和が全お菓子の数と同じなら答えはN, そうでないならN-1以下
if sum(a_list) == x:
    print(n)
    exit()

ans = 0

for i, a in enumerate(a_list):
    # 答えはN-1以下
    if i == len(a_list) - 1:
        break

    if x < a:
        break
    x -= a
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
#S= str(input())
#T= str(input())
N,X = map(int,input().split())
#N = int(input())
A = list(map(int,input().split()))
c=0
while X>=min(A):
    if len(A)==1:
        if X==A[0]:
            c+=1
            print(c)
            exit()
        else:
            print(c)
            exit()

    if X>=min(A):
        X-=min(A)
        A.remove(min(A))
        c+=1

print(c)

Submission status: Accepted

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

cs = np.sort(a).cumsum()

if cs[-1]<x:
    print(N-1)
elif cs[-1]==x:
    print(N)
else:
    print(np.where(cs<=x)[0].shape[0])

Submission status: Accepted

Solution code:
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n,x=i2()
a=intl()
a.sort()
b=0
for i in range(n):
	x-=a[i]
	if i<n-1:
		if x>=0:
			b+=1
		elif x<0:
			break
	elif i==n-1:
		if x==0:
			b+=1
print(b)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A,B=list(map(int,input().split()))
C=list(map(int,input().split()))
C.sort()
ans = 0
for i in C:
    if B >= i:
        ans+=1
        B-=i
    else:
        print(ans)
        exit()
if B > 0:
    ans-=1
print(ans)

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
ans = 0
i = 0
while n > i:
    an = a.pop()
    if x > an:
        x -= an
        ans += 1
    elif x == an:
        x -= an
        ans += 1
        break
    elif x < an:
        x -= an
        break
    i += 1
    if len(a) == 0:
        break
if x > 0:
    ans -= 1
print(ans)

Submission status: Accepted

Solution code:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
import itertools
def resolve():
    N,X=pin()
    A=lispin()
    A.sort()
    S=list(itertools.accumulate(A))
    #print(S)
    for i in range(N):
        if S[i]>X:
            print(i)
            return
    if S[-1]<X:print(N-1)
    else:print(N)
        
        

#%%submit!    
resolve()

Submission status: Accepted

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

a.sort()

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

Submission status: Accepted

Solution code:
import sys

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

a.sort()

s = [0 for i in range(N)]

for i in range(N):
    if i == 0:
        s[i] = a[i]
    else:
        s[i] = s[i-1] + a[i]

    if s[i] > x:
        print(i)
        sys.exit()

if s[-1] < x:
    print(N-1)
else:
    print(N)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np

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

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

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

A.sort()
ans = 0
for a in A:
    x -= a
    if x >= 0:
        ans += 1
    else:
        break
if x > 0 and ans:
    ans -= 1
print(ans)

Submission status: Accepted

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

if sum(a) < x:
    print(n - 1)
elif sum(a) == x :
    print(n)
else:
    a.sort()
    cnt = 0
    for i in range(n):
        x -= a[i]
        if x < 0:
            print(cnt)
            quit()
        cnt += 1

Submission status: Accepted

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

if sum(l) >= x:
    print(ans)
else:
    print(ans - 1)

Submission status: Accepted

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

Submission status: Accepted

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

child = 0
candy = 0

for i in a:
    candy += i
    if candy <= x:
        child += 1

if sum(a) < x:
    child -= 1

print(int(child))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n , x = map(int , input().strip().split())
a  = list(map(int , input().strip().split()))
a.sort()
if sum(a) < x:
  count = -1
else:
  count = 0

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Problem: https://atcoder.jp/contests/agc027/tasks/agc027_a
# Python 3rd Try

import sys
# from collections import defaultdict
# import heapq,copy
# from collections import deque


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 LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(childs, candies, happyNumber):
    result = 0
    happyNumber.sort()
    for ch_i in range(0, childs, +1):
        candies = candies - happyNumber[ch_i]
        if 0 <= candies:  # まだまだお菓子には余裕があります
            result = result + 1
        else:  # これ以上菓子が配れない
            return result
    # 全部終わってキッカリで無ければ最後の一人が不満
    if 0 != candies:
        return result - 1
    return result


if __name__ == "__main__":
    N, x = MI()
    AI = LI()
    print("{}".format(solver(N, x, AI)))

Submission status: Accepted

Solution code:
# A - Candy Distribution Again
count = 0
N, x = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
for i in range(N-1):
    x -= A[i]
    if(x < 0):
        break
    count += 1
if(x == A[N-1]):
    count += 1
        
print(count)

Submission status: Accepted

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

a_l.sort()
count = 0
for val in a_l[:-1]:
    x -= val
    if x < 0:
        break
    count += 1
if x == a_l[-1]:
    count += 1
print(count)

Submission status: Accepted

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

for a_i in a:
  x -= a_i
  if x<0:
    break
  else:
    ans+=1

if x>0:
  ans-=1

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(N):
    x = x - a_list[i]
    if x < 0:
        break
if i == N-1 and x == 0:
    i += 1

print(i)

Submission status: Accepted

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

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

Submission status: Accepted

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

a.sort()

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

if x >0:
    if cnt == 0:
        cnt = 0
    else:
        if cnt == len(a):
            cnt = cnt -1
        
print(cnt)

Submission status: Accepted

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

    ans = 0
    for _a in a[:-1]:
        x = x - _a
        if x >= 0:
            ans += 1
    if x == a[-1]:
        ans += 1
    print(ans)


resolve()

Submission status: Accepted

Solution code:
n, x = map(int, input().split())
a = sorted(list(map(int, input().split())))
if sum(a) < x:
    print(n-1)
    exit()
if sum(a) == x:
    print(n)
    exit()
idx = s = 0
while True:
    s += a[idx]
    if x == s:
        print(idx+1)
        exit()
    if x < s:
        print(idx)
        exit()
    idx += 1

Submission status: Accepted

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

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

Submission status: Accepted

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

i = 0

while x >= A[i]:
    x += -A[i]
    i += 1
    if i == N:
        i = (i-1 if x > 0 else i)
        break

print(i)

Submission status: Accepted

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

Submission status: Accepted

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

a.sort()

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

if sum(a) < x:
	print(n - 1)
	exit()

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N, x = map(int, input().split())
A = np.array(sorted(list(map(int, input().split()))))
cumsum = A.cumsum()

if cumsum[-1] < x:
    print(N - 1)
    exit()

ans = 0
for i in range(N):
    if cumsum[i] <= x:
        ans = i + 1
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    n, x = list(map(int, input().split()))
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    A = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    cnt = 0
    Asort = sorted(A)
    for i in range(n):
        if x >= Asort[i]:
            x -= Asort[i]
            cnt += 1
            if i == n-1 and x > 0:
                cnt -= 1
        else:
            break

    print(cnt)
resolve()

Submission status: Accepted

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

a = sorted(a)

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

Submission status: Accepted

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, x = list(map(int,_in[0].split(' ')))
    a_arr = list(map(int,_in[1].split(' ')))
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    a_arr.sort()
    for i in range(N):
        if sum(a_arr[:i+1]) > x:
            cnt = i
            break
        elif sum(a_arr[:i+1]) == x:
            cnt = i+1
            break
    else:
        cnt = N-1
    ## ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Accepted

Solution code:
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    n,x = I2()
    a = intl()
    a.sort()
    i = 0
    s = 0
    if sum(a) == x:
        print(n)
        exit()
    if sum(a) < x:
        print(n-1)
        exit()
    while s <= x:
        s += a[i]
        i += 1
    print(i-1)

Submission status: Accepted

Solution code:
# Problem: https://atcoder.jp/contests/agc027/tasks/agc027_a
# Python 2nd Try

import sys
# from collections import defaultdict
# import heapq,copy
# from collections import deque


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 LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(haveManyPiaceOFCandy, AI):
    result = 0
    AI.sort()
    for j in range(len(AI)):
        haveManyPiaceOFCandy = haveManyPiaceOFCandy - AI[j]
        if haveManyPiaceOFCandy < 0:
            return result
        else:
            result = result + 1
    # algorithm
    if 0 < haveManyPiaceOFCandy:
        result = result - 1
    return result


if __name__ == "__main__":
    _, X = MI()
    AI = LI()
    print("{}".format(solver(X, AI)))

Submission status: Accepted

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

a.sort()
c = 0
i = 0
while(True):
    if(i >= n - 1):
        break
    if(x < a[i]):break
    c += 1
    x -= a[i]
    i += 1
if(x == a[i]):c += 1
print(c)

Submission status: Accepted

Solution code:
N,x = map(int,input().split())
As = list(map(int,input().split()))
As.sort()
cnt = 0
ans = 0
while x > 0:
    if cnt + 1 == N and x != As[cnt]:
        x = 0
    elif x >= As[cnt]:
        x -= As[cnt]
        ans+=1
    cnt += 1
else:
    print(ans)

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 i == N-1 and x > A[i]:
    break
  if x >= A[i]:
    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()))
c = 0
a_sorted = sorted(a)

for i in range(n):
    x -= a_sorted[i]
    if x > 0 and i <= n-2:
        c += 1
    elif x == 0:
        c += 1
    else:
        break

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,x=map(int,input().split())
a=sorted(map(int,input().split()))
c=0
if x>sum(a):
  print(N-1)
  exit()

while x>0 and c<=N-1:
  if x-a[c]>=0:
    x-=a[c]
    c+=1
  else:
    break


print(c)

Submission status: Accepted

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

S = 0
c = 0

for i in range(N):
  S += A[i]
  
if S < x:
  print(N-1)
else:
  for i in range(N):
    b = x - A[i]
    if b > 0:
      c += 1
      x -= A[i]
    elif b == 0:
      c += 1  
      break
    else:
      break
  print(c)

Submission status: Accepted

Solution code:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n, x = map(int, input().split())
a = readints()
b = sorted(a)
cnt = 0
for i in range(len(b)):
    if b[i] <= x:
        x -= b[i]
        cnt += 1
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()
S = 0
count = 0

for i in range(N):
  S += A[i]
  
if S < x:
  print(N-1)
  exit()
else:
  for i in range(N):
    b = x - A[i]
    if b > 0:
      count += 1
      x -= A[i]
    elif b == 0:
      count += 1  
      break
    else:
      break
  print(count)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, x = map(int, input().split())
tmp = x
A = list(map(int, input().split()))
ans = 0
A.sort()
for a in A:
  if x >= a:
    x -= a
    ans += 1
if tmp > sum(A):
  ans -= 1
print(ans)

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-1):
    if x-A[i]>=0:
        cnt+=1
        x-=A[i]
    else:
        break
if x-A[N-1]==0:
    cnt+=1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,x = readInts()
    A = sorted(readInts())
    now = 0
    cnt = 0
    for i in range(n):
        if now + A[i] <= x:
            if i == n-1:
                if now + A[i]== x:
                    cnt += 1
                else:
                    pass
            else:
                now += A[i]
                cnt += 1
        else:
            break
    print(cnt)
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import itertools
import bisect
N,x = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
cumsum = list(itertools.accumulate(A))
ans = bisect.bisect_right(cumsum,x)

if ans == N:
  rest = cumsum[-1] - x
  if rest != 0:
    ans -= 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left

#======================================================#

def main():
    n, x = MII()
    aa = MII()
    aa.sort()
    cnt = 0
    if x > sum(aa):
        cnt -= 1
    for a in aa:
        if x >= a:
            x -= a
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

count = 0
for ai in a:
    if ai <= x:
        x -= ai
        count += 1
    else:
        break

# 全員に配り終えても余っている場合は、残りのクッキーを1人にわたす
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.sort()
ans=0
for a in A[:-1]:
  x-=a
  if x>=0:
    ans+=1
  else:
    break
if A[-1]==x:
  ans+=1
print(ans)

Submission status: Accepted

Solution code:
# Problem: https://atcoder.jp/contests/agc027/tasks/agc027_a
# Python 1st Try

import sys
# from collections import defaultdict
# import heapq,copy
# from collections import deque


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 LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(allChild, haveCandy, eachHappy):
    result = 0
    allHappyCount = 0
    eachHappy.sort()
    for j in range(len(eachHappy)):
        allHappyCount = allHappyCount + eachHappy[j]
    # algorithm
    # print("{}".format(allHappyCount))
    # if allHappyCount < haveCandy:
    #    result = allChild - 1
    #     return result
    for j in range(0, allChild, +1):
        haveCandy = haveCandy - eachHappy[j]
        if haveCandy < 0:
            return result
        else:
            result = result + 1
    if 0 < haveCandy:
        result = result - 1
    return result


if __name__ == "__main__":
    N, X = MI()
    childHappyCount = LI()
    print("{}".format(solver(N, X, childHappyCount)))

Submission status: Accepted

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

a.sort()
distributed = 0
beGlads = 0

for i in range(N):
    if distributed + a[i] > x:
        break
    else:
        distributed += a[i]
        beGlads += 1

print(beGlads if sum(a) >= x else beGlads - 1)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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