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: Runtime Error

Solution code:
N = int(input())
x = int(input())
cage = []
for i in range(N):
    nu = int(input())
    cage.append(nu)
ans=0
for i in range(N):
    ind = cage.index(min(cage))
    if(min(cage) > x):
        break
    x = x - min(cage)
    cage[ind] = "no"
    ans += 1
if x>0:
    ans = ans - 1
print(ans)
print(x,cage)

Submission status: Runtime Error

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

nokori = x - min(child_list)
please_child = 0 
while nokori >=0:
    please_child +=1
    mini = min(child_list)
    child_list.remove(mini)
    if child_list == []:
        break
    if len(child_list) == 1:
        if nokori == min(child_list):
            please_child += 1
        if nokori > min(child_list):
            break
    else:    
        nokori -= min(child_list)
print(please_child)

Submission status: Runtime Error

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

nokori = x - min(child_list)
please_child = 0 
while nokori >=0:
    please_child +=1
    mini = min(child_list)
    child_list.remove(mini)
    if child_list == []:
        break
    nokori -= min(child_list)
print(please_child)

Submission status: Runtime Error

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

nokori = x - min(child_list)
please_child = 0 
while nokori >0:
    please_child +=1
    mini = min(child_list)
    child_list.remove(mini)
    if child_list == []:
        break
    nokori -= min(child_list)
print(please_child)

Submission status: Runtime Error

Solution code:
y = x
cnt = 0
for ai in a:
    if y - ai >= 0:
        y -= ai
        cnt += 1
if y and cnt == n:
    print(cnt - 1)
else:
    print(cnt)

Submission status: Runtime Error

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

b = []
for i in range(N):
    b.append(i)
c = 0
d = []
for i in range(N):
    d.append(i)
for i in range(N):
    b[i] = d
    for j in range(N):
        d[j] += a[j]
for i in range(N):
    if b[i] <= X:
        c += 1
print(c)

Submission status: Runtime Error

Solution code:
import sys


# n = int(sys.stdin.readline().strip())
#
# line = sys.stdin.readline().strip()
# values = list(map(int, line.split()))


def main():
    line = sys.stdin.readline().strip()
    values = list(map(int, line.split()))
    N, x = values[0], values[1]
    line = sys.stdin.readline().strip()
    values = list(map(int, line.split()))
    d = {}
    d = [[-1 for j in range(x)] for i in range(N)]

    def rec(i, j):
        res = 0
        if d[i][j] >= 0:
            return d[i][j]
        if i == N:
            if j == 0:
                return 0
            else:
                return -1
        elif j < values[i]:
            res = rec(i + 1, j)
        else:
            res = max(rec(i + 1, j), rec(i + 1, j - values[i]) + 1)
        d[(i, j)] = res
        return res

    res = rec(0, x)
    if res == -1:
        print(0)
    else:
        print(res)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

ch = 0 # 満足した子供の数

while x != 0: # お菓子がある間ループする
    if x - a[i] < 0: # a[i]個は渡せない
        x = 0
    else:
        x -= a[i]
        ch += 1

print(ch)

Submission status: Runtime Error

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

li = 0
li = list(map(int,input().split()))



j = 0
k = 0
while k < N - 1:
    if x > li[k]:
        j += 1
        x = x - li[k]
        k += 1
    else:
        #x = x - li[k]
        k += 1
if x == li[k] or li[k] == 0:
    j += 1
print(str(j))

return 0

Submission status: Runtime Error

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

count = 0

a = sorted(a)

b = []

t = 0

for y in a:
  t += y
  if t>N:
    break
  else:
  b.append(y)
    
print(len(b))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

count = 0

a = np.array(sorted(a))

acum = a.cumsum()

for i,y in enumerate:
  if y>=x:
    count = i
    break
    
print(min(count,N))

Submission status: Runtime Error

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

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

print(ans)

Submission status: Runtime Error

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

li = 0
li = list(map(int,input().split()))



j = 0
k = 0
while k < N - 1:
    if x > li[k]:
        j += 1
        x = x - li[k]
        k += 1
    else:
        #x = x - li[k]
        k += 1
if x == li[k]:
    j += 1
print(str(j))

return 0

Submission status: Runtime Error

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

Submission status: Runtime Error

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

al.sort()

used = 0
ans = 0
for a in enumerate(al:
    if used+a > x:
        break
    used += a
    ans += 1

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

arr.sort()
cnt = 0
for ele in arr:
    if x < ele:
        break
    x -= ele
    cnt += 1

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

print(cnt)

Submission status: Runtime Error

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


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



j = 0
k = 0
while k < N:
    if x > li[k]:
        j += 1
        x = x - li[k]
        k += 1
    else:
        x = x - li[k]
        k += 1


print(str(j))

Submission status: Runtime Error

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

Submission status: Runtime Error

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


i = 0
while i < N :
    li = list(map(int,input().split()))
    i += 1


j = 0
k = 0
while k < N:
    if x > li[k]:
        j += 1
        x = x - li[k]
        k += 1
    else:
        x = x - li[k]
        k += 1


print(str(j))

Submission status: Runtime Error

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

arr.sort()
cnt = 0
for ele in arr:
    if x < ele:
        break
    x -= ele
    cnt += 1

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

print(cnt)

Submission status: Runtime Error

Solution code:
N, x = map(int, input().split())
alist = list(map(int, input().split()))
alist.sort()
 
def counter(x, alist):
  count = 0
  while x > 0:
      if alist:
          tmp = alist.pop(0)
          x = x - tmp
          if x == 0:
              return count + 1
          elif x > 0:
              count += 1
          else:
              return count
      else:
          return count - 1
print(counter(x, alist))
N, x = map(int, input().split())
alist = list(map(int, input().split()))
alist.sort()

def counter(x, alist):
  count = 0
  while x > 0:
      if alist:
          tmp = alist.pop(0)
          x = x - tmp
          if x == 0:
              return count + 1
          elif x > 0:
              count += 1
          else:
              return count
      else:
          return count - 1
print(counter(x, alist))

Submission status: Runtime Error

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

for x>0:
  if x - min(child_list) > 0:
    please_child +=1
    child_list = child_list.remove(min(child_list))
  if child_list == []:
    break
  if x - min(child_list) =< 0:
    break
print(please_child)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
headData = input().split()
candyTotal = int(headData[1])
childList = [ int(n) for n in input().split()]
childList.sort()
childTotal = sum(childList)

if candyTotal == childTotal:
    print(len(childList))
elif candyTotal == childTotal:
    print(len(childList)-1)
else:
    answer=0
    childSum=0
    for child in childList:
        childSum = childSum + child
        if childSum > candyTotal:
            print(answer)
            exit()
        else:
            answer = answer + 1
print(answer-1)

Submission status: Runtime Error

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

for x>0:
  if x - min(child_list) > 0:
    please_child +=1
    child_list = child_list.pop(min(child_list))
  if child_list == []:
    break
  if x - min(child_list) =< 0:
    break
print(please_child)

Submission status: Runtime Error

Solution code:
n, x = map(int, input().split())
a = sorted([*map(int, input().split())])
ans, i = 0, 0
while i < (n - 1):
    if x - a[i] >= 0:
        x -= a[i]
        ans += 1
    else:
        break
    i += 1
if x == a[i]:
	ans += 1
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a=sorted(map(int,raw_input().split()))
ans=0
for i in xrange(N):
  x-=a[i]
  if x<0 or i==N-1 and x>0:
    break
  else:
    ans+=1
print ans

Submission status: Runtime Error

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

Submission status: Runtime Error

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

for x>0:
  if x - min(child_list) > 0:
    please_child +=1
    child_list = child_list.pop(min(child_list))
  else:
    break
print(please_child)

Submission status: Runtime Error

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