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:
def a_candy_distribution_again(N, X, A):
    A.sort()
    ans = 0
    for a in A:
        if a <= X:
            ans += 1
            X -= a
    if X > 0 and ans > 0:
        ans -= 1
    return ans

N, X = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(a_candy_distribution_again(N, X, A))

Submission status: Wrong Answer

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

res = 0
for i in a:
    if x<=i:
        break
    x -= i
    res += 1
if x==0:
    print(res)
else:
    print(max(res-1,0))

Submission status: Wrong Answer

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

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

def score(a, m, x):
    ans = x*(n+m)
    l = n//m
    for i in range(n):
        t = (n-1-i)//m
        if i < m:
            ans += ((t+2)**2) * a[i]
        else:
            ans += ((t+2)**2) * (a[i] - a[i-m])
    for i in range(m):
        ans += a[n-1-i]
    return ans
        
def search(left, right, l_score, r_score, a, x):
    tri = (right-left)//3
    u_score = score(a, left+tri, x)
    v_score = score(a, left+tri*2, x)
    if right-left <= 3:
        return min(u_score, v_score, l_score, r_score)
    elif l_score < u_score:
        return search(left, left+tri, l_score, u_score, a, x)
    elif r_score < v_score:
        return search(left+tri*2, right, v_score, r_score, a, x)
    elif u_score < v_score:
        return search(left, left+tri*2, l_score, v_score, a, x)
    else:
        return search(left+tri, right, u_score, r_score, a, x)
    
    
def sub_search(r, a, x):
    ans = score(a, r//2+1, x)
    #print(ans)
    for i in range(r//2):
        j = r//2 - i
        ddd = score(a, j, x)
        #print(ddd)
        if ddd <= ans:
            ans = ddd
        else:
            break
    return ans
    
    
#k = search(1, n, score(a, 1, x), score(a, n, x), a, x)
k = sub_search(n, a, x)
print(k)

Submission status: Wrong Answer

Solution code:
N, X = tuple(map(int, input().split()))
xs = list(sorted(map(int, input().split())))
print(N, X, xs)

def atGomi(k, x, energy, rest):
    print(k, x, energy, rest)
    if k == 0:
        if len(rest) == 0:
            return energy + 100 + (1+1) ** 2 * x + 100
        else:
            return atGomi(1, rest[-1], energy + 100 + (1+1) ** 2 * (x-rest[-1]), rest[:-1])
    if len(rest) == 0:
        # hirou
        e_hirou = energy + 100 + (k+1+1) ** 2 * x + 100
        e_hirowanai = energy + ((k+1) ** 2 * x) + 100 + 100 + (1+1) ** 2 * x + 100
        #e_hirowanai = atGomi(0, rest[-1], energy + k ** 2 + 100, rest[:len(rest)-1])
        return min(e_hirou, e_hirowanai)
    else:
        flist = list(filter(lambda i: i < x, rest))
        if len(flist) == 0:
            e_hirou = atGomi(0, rest[-1], energy + 100 + (k+1+1) ** 2 * x, rest[:-1])
            e_hirowanai = atGomi(0, rest[-1], energy + (k+1)**2 * x, sorted(rest[:-1]+[x]))
        else:
            next_x = max(flist)
            next_rest = list(filter(lambda i: i != next_x, rest))
            print(next_x, next_rest)
            exit(0)
            e_hirou = atGomi(k+1, next_x, energy + 100 + (k+1+1) ** 2 * (x-next_x), next_rest)
            e_hirowanai = atGomi(k, next_x, energy + (k+1)**2 * (x-next_x), sorted(next_rest+[x]))
            return min(e_hirou, e_hirowanai)

if N == 0 or len(xs) == 0:
    print(0)
else:
    xi = xs.pop()
    print(xi, xs)
    minGomi = atGomi(0, xi, 0, xs)
    print(minGomi)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

import itertools
A=[1,0]
B={}
C={}
max=0
for i in itertools.product(A, repeat=N):
  B[i]=i.count(1)
  
for k, v in sorted(B.items(), key=lambda x: -x[1]):
  C[k]=v

for k, v in C.items():
    if v==max:
      break
    sum=0
    for j in range(N):
        sum=sum+k[j]*int(a[j])
        if sum>x:
          break
    if sum==x:
        max=v
        break
    if sum<x and v>0:
        max=v-1
        
  
print(max)

Submission status: Wrong Answer

Solution code:
N, X = map(int, input().split())
A = [int(x) for x in input().split()]
count = 0
m = 0
def Candy (i, rest, count):
    global m
    #print(i, rest, count)
    #最後に余った
    if i == N and rest > 0:
        #print("remain")
        if count > 0:
            m = max(m, count - 1)
            return m
        else:
            m = max(m, count)
            return m

    #最後に余らなかった
    if i == N and rest == 0:
        #print("just")
        m = max(m, count)
        return m

    if i == N and rest < 0:
        #print("over")
        return False
    
    #配って次へ   
    if (Candy(i+1, rest-A[i], count+1)):
        #print("A", i, rest, count)
        return True
  
    #配らないで次へ
    if (Candy(i+1, rest, count)):
        #print("B", i, rest, count)
        return True
    
    return False
Candy(0, X, count)
print(m)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a = np.array(a, int)

a = np.sort(a)

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a = np.array(a, int)

a = np.sort(a)

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

Submission status: Wrong Answer

Solution code:
N,x=map(int,input().split())
a=list(input().split())
import itertools
A=[1,0]
B={}
C={}
max=0
for i in itertools.product(A, repeat=N):
  B[i]=i.count(1)
  
for k, v in sorted(B.items(), key=lambda x: -x[1]):
  C[k]=v

for k, v in C.items():
    if v==max:
      break
    sum=0
    for j in range(N):
        sum=sum+k[j]*int(a[j])
        if sum>x:
          break
    if sum==x:
        max=v
        break
    if sum<x and v>0:
        max=v-1
        
  
print(max)

Submission status: Wrong Answer

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

a = [int(i) for i in input().strip().split()]
a.sort()

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

Submission status: Wrong Answer

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

a = [int(i) for i in input().strip().split()]
a.sort()

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

Submission status: Wrong Answer

Solution code:

N, V = list(map(int, input().split()))
C = list(map(int, input().split()))
assert len(C)==N

W = [1 for i in range(N)]
res = [0 for i in range(N)]
F = [0 for i in range(V+1)]

def pack01_lo(F, c, w):
    for v in range(c, V+1)[::-1]:
        F[v] = max(F[v], F[v-c]+w)

for i in range(N):
    lo = max(V-sum(C[i:]), C[i])
    pack01_lo(F, lo, W[i])

#s = sum(C)
#print(F)
print(F[-1])

Submission status: Wrong Answer

Solution code:
import numpy

N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
a_sum = numpy.cumsum(a)
ans = numpy.sum(a_sum <= x)

if ans >= 1 and a_sum[ans-1] != x:
    if ans < N and a_sum[ans] - a_sum[ans - 1] not in a_sum[0:ans]:
        ans -= 1
    elif a_sum[-1] < x:
        ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
N,x=map(int,input().split())
a=list(input().split())
import itertools
A=[1,0]
B={}
C={}
max=0
for i in itertools.product(A, repeat=N):
  B[i]=i.count(1)
  
for k, v in sorted(B.items(), key=lambda x: -x[1]):
  C[k]=v

for k, v in C.items():
    if v==max:
      break
    sum=0
    for j in range(N):
        sum=sum+k[j]*int(a[j])
    if sum==x:
        max=v
        break
    if sum<x and v>0:
        max=v-1
        
  
print(max)

Submission status: Wrong Answer

Solution code:
N, x=map(int,input().split())
a=[int(i) for i in input().split()]
a.sort()
j=1
S=a[0]
while (S<x)and(j<N):
  S=S+a[j]
  j=j+1

if S==x:
  print(j)
elif S>x:
  print(j-1)
else:
  print(j)

Submission status: Wrong Answer

Solution code:
a = input().split()
a = [int(i) for i in a]
b = input().split()
b = [int(i) for i in b]
b = sorted(b)
output = 0
end = False

for i in range(len(b)-  1):
	print(a[1], b[i])
	if a[1] - b[i] > 0:
		a[1] += -b[i]
		output += 1
	elif(a[1] - b[i] == 0):
		output += 1
		end = True
		break
	else:
		end = True
		break
		
if end == False:
	if a[1] - b[-1] == 0:
		output += 1
		 
print(output)

Submission status: Wrong Answer

Solution code:
N,x=map(int,input().split())
a=list(input().split())
Y=0
import itertools
A=[1,0]
B={}
C={}
max=0
for i in itertools.product(A, repeat=N):
  B[i]=i.count(1)
  
for k, v in sorted(B.items(), key=lambda x: -x[1]):
  C[k]=v

for k, v in C.items():
      
    sum=0
    for j in range(N):
        sum=sum+k[j]*int(a[j])
    if sum==x:
        max=v
        Y=1
        break
    if Y==2:
        Y=1
        break
    if sum<x and v>0:
        max=v-1
        Y=2 
  

print(max)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
dp = [[]]
a.sort()
ans = 0
f = False
for b in a:
    if b <= x:
        ans += 1
        x -= b
        f = True
    else:
        f = False
if b > 0 and f:
    ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
N, x=map(int,input().split())
a=[int(i) for i in input().split()]
a.sort()
j=1
S=a[0]
while (S<x)and(j<N-1):
  S=S+a[j]
  j=j+1

if S==x:
  print(j)
elif S>x:
  print(j-1)
else:
  print(j+1)

Submission status: Wrong Answer

Solution code:
a = input().split()
a = [int(i) for i in a]
b = input().split()
b = [int(i) for i in b]
b = sorted(b)
output = 0
end = False

for i in range(len(b)-  1):
	if a[1] - b[i] > 0:
		a[1] += -b[i]
		output += 1
	elif(a[1] - b[i] == 0):
		output += 1
		end = True
		break
	else:
		end = True
		break
		
if end == False:
	if a[1] - b[-1] < 0:
		output -= 1
	elif a[1] - b[-1] > 0:
		output -= 1
	else:
		output += 1
		 
print(output)

Submission status: Wrong Answer

Solution code:
nx = map(int, raw_input().split())
ai= map(int, raw_input().split())
ailen=len(ai)
sorted(ai)
counti=0
ans=0
for i in ai:
    counti=counti+1
    nx[1]=nx[1]-i
    if nx[1]>=0:
        ans=ans+1
    else:
        nx[1]=nx[1]+i
        break
if ailen==counti and nx[1]>0:
    ans=ans-1
if ans<0:
    ans=0
print ans

Submission status: Wrong Answer

Solution code:
a = input().split()
a = [int(i) for i in a]
b = input().split()
b = [int(i) for i in b]
b = sorted(b)
output = 0
end = False

for i in range(len(b)-  1):
	if a[1] - b[i] > 0:
		a[1] += -b[i]
		output += 1
	elif(a[1] - b[i] == 0):
		output += 1
		end = True
		break
	else:
		end = True
		pass
		
if end == False:
	if a[1] - b[-1] < 0:
		output -= 1
	elif a[1] - b[-1] > 0:
		output -= 1
	else:
		output += 1
		 
print(output)

Submission status: Wrong Answer

Solution code:
in1 = input()
in2 = input()
N, x = in1.split()
N = int(N)
x = int(x)
a = list()
for i in in2.split():
  a.append(int(i))
a.sort()
count = 0
for ai in a:
  if x > ai:
    count += 1
    x -= ai
  elif x == ai:
    count += 1
    x -= ai
    break
  else:
    break
if x != 0 and count > 0:
  count -= 1
count += 1
print(count)

Submission status: Wrong Answer

Solution code:
in1 = input()
in2 = input()
N, x = in1.split()
N = int(N)
x = int(x)
a = list()
for i in in2.split():
  a.append(int(i))
a.sort()
count = 0
for ai in a:
  if x > ai:
    count += 1
    x -= ai
  elif x == ai:
    count += 1
    x -= ai
    break
  else:
    break
if x != 0 and count > 0:
  count -= 1
print(count)

Submission status: Wrong Answer

Solution code:
import copy

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

res_count = 0

def rec_count(a_list, ix=0):
  global res_count
  if len(a_list) == 0 or len(a_list) <= res_count:
    return None
  sum_a = sum(a_list)
  if sum_a == x:
    return len(a_list)
  if x > sum_a:
    return len(a_list) - 1
  c_list = [0]
  for i in range(ix, len(a_list)):
    tmp_a_list = copy .deepcopy(a_list)
    del tmp_a_list[ix]
    tmp_count = rec_count(tmp_a_list, i)
    if tmp_count is not None:
      c_list.append(tmp_count)
      if tmp_count > res_count:
        res_count = tmp_count
  return max(c_list)

tmp_count = rec_count(a_list)
if tmp_count > res_count:
  res_count = tmp_count
print(res_count)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

N, x = input().split()
a = input().split()

N = int(N)
x = int(x)
a = list(sorted((map(int, a))))

if x < min(a) or x == 0:
    print(0)
elif x >= sum(a):
    print(N)
else:
    for i in range(N-1, 0, -1):
        m = sum(a[:i])
        #m = min(map(sum, combinations(a, i)))
        if x >= m:
            print(i)
            break

Submission status: Wrong Answer

Solution code:
nx = map(int, raw_input().split())
ais= map(int, raw_input().split())
ailen=len(ais)
ai=sorted(ais)
counti=0
ans=0
for i in ai:
    counti=counti+1
    nx[1]=nx[1]-i
    if nx[1]>=0:
        ans=ans+1
    else:
        nx[1]=nx[1]+i
        break
if ailen==counti and nx[1]>0:
    ans=ans-1
if ans<0:
    ans=0
print ans

Submission status: Wrong Answer

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

if len(child_list) == 1:
    if x > min(child_list):
        please_child = 0
    elif x == min(child_list):
        please_child = 1
elif len(child_list) > 1:
    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: Wrong Answer

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

b = []
for _ in range(N):
    b.append(0)
    
c = 0

for i in range(N):
    for j in range(i+1):
        b[i] += a[j]

for k in range(N):
    if b[k] <= X:
        c += 1
print(c)

Submission status: Wrong Answer

Solution code:
import numpy

N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
a_sum = numpy.cumsum(a)
ans = numpy.sum(a_sum <= x)

if ans >= 1 and a_sum[ans-1] != x:
    ans -= 1

print(ans)

Submission status: Wrong Answer

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

ans = 0
use_list = []
for i in range(2**N):
    use_list.append(list(map(int, list(bin(i)[2::].zfill(N)))))
for u in use_list:
    s = 0
    
    for i in range(N):
        if u[i] == 1:
            s += a[i]
    if s <= x:
        ans = max(ans, sum(u))
print(ans)

Submission status: Wrong Answer

Solution code:
a = input().split()
a = [int(i) for i in a]
b = input().split()
b = [int(i) for i in b]
b = sorted(b)
output = 0
ok = False
if a[1] < b[0]:
     print (0)
     ok = True

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

if ok == False:
     print(output)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
in1 = input()
in2 = input()
N, x = in1.split()
N = int(N)
x = int(x)
a = list()
for i in in2.split():
  a.append(int(i))
a.sort()
count = 0
for ai in a:
  if x > ai:
    count += 1
    x -= ai
  elif x == ai:
    count += 1
    x -= ai
    break
  else:
    break
if x > 0 and count > 0:
  count -= 1
print(count)

Submission status: Wrong Answer

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

b = []
for i in range(N):
    b.append(0)
    
c = 0

for i in range(N):
    for j in range(i+1):
        b[i] += a[j]

for k in range(N):
    if b[k] <= X:
        c += 1
print(c)

Submission status: Wrong Answer

Solution code:
in1 = input()
in2 = input()
N, x = in1.split()
N = int(N)
x = int(x)
a = list()
for i in in2.split():
  a.append(int(i))
a.sort()
count = 0
for ai in a:
  if x > ai:
    count += 1
    x -= ai
  elif x == ai:
    count += 1
    x -= ai
    break
  else:
    break
if 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.sort()

b = []
for i in range(N):
    b.append(0)
    
c = 0

for i in range(N):
    for j in range(i+1):
        b[i] += a[j]

for i in range(N):
    if b[i] <= X:
        c += 1
print(c)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
# encoding: utf-8
# N = int(input())
# S = input()
# N, M = map(int, input().split())
# A = list(map(int, input().split()))

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

def recsearch(i, x_tmp):
    # print("#", i, x_tmp)
    if i == N:
        if x_tmp > 0: ret = -1
        else: ret = 0
    elif x_tmp < A[i]: ret = recsearch(i + 1, x_tmp)
    else: ret = max((recsearch(i + 1, x_tmp - A[i]) + 1, recsearch(i + 1, x_tmp)))
    return ret
        
print(max(0, recsearch(0, x)))

Submission status: Wrong Answer

Solution code:
in1 = input()
in2 = input()
N, x = in1.split()
N = int(N)
x = int(x)
a = list()
for i in in2.split():
  a.append(int(i))
a.sort()
count = 0
for ai in a:
  if x > ai:
    count += 1
    x -= ai
  elif x == ai:
    count += 1
    break
  else:
    break
print(count)

Submission status: Wrong Answer

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


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

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

a.sort()
ans = 0
for b in a:
    if b <= x:
        ans += 1
        x -= b
if x != 0 and ans > 1:
    ans -= 1
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy

N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
a_sum = numpy.cumsum(a)
ans = numpy.sum(a_sum <= x)

if ans > 1 and a_sum[ans-1] != x:
    ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:

in1 = input()
in2 = input()
N, x = in1.split()
N = int(N)
x = int(x)
a = list()
for i in in2.split():
  a.append(int(i))
a.sort()
count = 0
for ai in a:
  if x > ai:
    count += 1
    x -= ai
  elif x == ai:
    count += 1
    break
  else:
    break
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

b = []
for i in range(N):
    b.append(0)
    
c = 0

d = []
for i in range(N):
    d.append(0)


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

Submission status: Wrong Answer

Solution code:
from itertools import combinations

N, x = input().split()
a = input().split()

N = int(N)
x = int(x)
a = list(map(int, a))

if x < min(a):
    print(0)
elif x >= sum(a):
    print(N)
else:
    for i in range(N, 0, -1):
        m = min(map(sum, combinations(a, i)))
        if x >= m:
            print(i)
            break

Submission status: Wrong Answer

Solution code:
m,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
cnt=0
res=0
for i in a:
    cnt+=i
    if cnt > x:
        break
    res+=1
if a[0] > x:
    res=0
print(res)

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
a_list = list(map(int,input().split()))
a_list_sort = sorted(a_list)
#print(a_list)
#print(a_list_sort)
count = 0

if sum(a_list) <= x :
	count = N-1
else:
	for i in range(N):
		if sum(a_list_sort[:i+1]) <= x:
			continue	
		else:
			count = i
			break
print(count)

Submission status: Wrong Answer

Solution code:
import numpy

N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
a_sum = numpy.cumsum(a)
ans = numpy.sum(a_sum < x)

if x in a_sum:
    ans += 1

print(ans)

Submission status: Wrong Answer

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

A = sorted(A)

def solve(a, x, j):
    cnt = 0
    f = False
    for i in range(j, n):
        if x >= a[i]:
            x -= a[i]
            cnt += 1
        else:
            cnt += 1
            f = True
        if f or x == 0:
            break
    if x == 0:
        return cnt
    else:
        return cnt - 1
    
res = 0
for i in range(n):
    res = max(res, solve(A[::-1], X, i))
print(res)

Submission status: Wrong Answer

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

b = []
for i in range(N):
    b.append(0)
    
c = 0

d = []
for i in range(N):
    d.append(0)


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

Submission status: Wrong Answer

Solution code:
nx = map(int, raw_input().split())
ais= map(int, raw_input().split())
ailen=len(ais)
ai=sorted(ais)
counti=0
ans=0
for i in ai:
    counti=counti+1
    nx[1]=nx[1]-i
    if nx[1]>=0:
        ans=ans+1
    else:
        nx[1]=nx[1]+i
        break
if ailen==counti and nx[1]>0:
    ans=ans-1
print ans

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

l1 = input().split()
l2 = input().split()

n = int(l1[0])
a = int(l1[1])
l2.sort()

i = 0
out = 0

for i in range(0,n):
    a = a - int(l2[i]) 
    if a >= 0:
        out = out + 1
    
print(out)

Submission status: Wrong Answer

Solution code:
xy=input().split()
n=int(xy[0])
x=int(xy[1])
l=input().split()
l.sort()
sum=0
i=0
while sum<x and i+1<=n:
    sum=sum+int(l[i])
    i=i+1
#    print(i,sum)
if sum>x:
    print(i-1)
elif sum<x:
    print(i-1)
else:
    print(i)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def cand(amari, a, count):
    #print("first", amari, a, count)
    if len(a)!=0:
        ma=max(a)
        a.remove(ma)
    else:
        print(count)
        exit()
    if amari>=ma:
        amari-=ma
        count+=1
        if len(a)==0 and amari!=0:
            count-=1
        #print("111", amari, ma, a, count)
        cand(amari, a, count)
    else:
        cand(amari, a, count)




[n, x]=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
count=0
cand(x, a, count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A = sorted(A)

def solve(a, x, j):
    cnt = 0
    f = False
    for i in range(j, n):
        if x >= a[i]:
            x -= a[i]
            cnt += 1
        else:
            cnt += 1
            f = True
        if f:
            break
    if x == 0:
        return cnt
    else:
        return cnt - 1
    
res = 0
for i in range(n):
    res = max(res, solve(A[::-1], X, i))
print(res)

Submission status: Wrong Answer

Solution code:
from itertools import combinations

N, x = input().split()
a = input().split()

N = int(N)
x = int(x)
a = list(map(int, a))

if x < min(a):
    print(0)
elif x >= sum(a):
    print(N)
else:
    for i in range(N, 0, -1):
        c = list(combinations(a, i))

        for j in c:
            if x >= sum(j):
                print(i)
                exit(0)

Submission status: Wrong Answer

Solution code:
# child_count = 3
# candy_sum = 70
# requirement_list = [20, 30, 10]
N = 2 # 入力は2行
# for i in range(N):
#     line = input()
#     print(type(line)) # str
#     print(line) # 1行目だけ
for i in range(N):
    line = input() # 入力を1行受け取る
    if i == 0: # 1行目
        child_count, candy_sum = map(int, line.split())
    else: # 2行目
        requirement_list = list(map(int, line.split()))
# print(child_count, candy_sum, requirement_list)
satisfied_count = 0
requirement_list.sort() # 昇順に並び替え
requirement_list.reverse() # 降順に並び替え
# print(requirement_list)
# 最後の人を考慮漏れ
for i in range(child_count): # len(requirement_list) == child_count
    requirement = requirement_list[i]
    # print(i, candy_sum, requirement)
    if i == child_count-1: # 最後の人(残りのお菓子がほしい数と一致するか)
        if requirement == candy_sum:
            satisfied_count += 1
    else: # 1人目からchild_count-1人目まで
        if requirement <= candy_sum:
            candy_sum -= requirement
            satisfied_count += 1
# for requirement in requirement_list:
#     if requirement <= candy_sum:
#         candy_sum -= requirement
#         satisfied_count += 1
#         print(requirement, candy_sum)
#     # requirement > candy_sumのときは何もしない。
#     # candy_sum = 20のケースがあるので、
#     # [30, 20, 10]のときに最初が30だからといってbreakもしない
print(satisfied_count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy

N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
a_sum = numpy.cumsum(a)
ans = numpy.sum(a_sum <= x)

if x not in a_sum:
    ans -= 1
if ans < 0:
    ans = 0

print(ans)

Submission status: Wrong Answer

Solution code:
nx = map(int, raw_input().split())
ais= map(int, raw_input().split())
ailen=len(ais)
ai=sorted(ais)
counti=0
ans=0
for i in ai:
    counti=counti+1
    nx[1]=nx[1]-i
    if nx[1]>=0:
        ans=ans+1
    else:
        if nx[1]<0:
            nx[1]=nx[1]+i
        break
if ailen==counti and nx[1]>0:
    ans=ans-1
print ans

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    N,x=[int(i) for i in input().split()]
    a=input().split()
    k=0
    while True:
        if x>=int(min(a)):
            if len(a)==1:
                if x>int(min(a)):
                    k-=1
            x=x-int(min(a))
            a.remove(min(a))
            k+=1

            if len(a)==0:
                break
        else:
            break
    print(k)
main()

Submission status: Wrong Answer

Solution code:
xy=input().split()
n=int(xy[0])
x=int(xy[1])
l=input().split()
l.sort()
sum=0
i=0
while sum<x and i+1<=n:
    sum=sum+int(l[i])
    i=i+1
#    print(i,sum)
if sum<x:
    print(i)
else:
    print(i)

Submission status: Wrong Answer

Solution code:
import numpy

N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
a_sum = numpy.cumsum(a)
ans = numpy.sum(a_sum <= x)
if a_sum[ans-1] != x:
    ans -= 1

print(ans)