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:
import copy
import itertools

N, X = map(int, input().split())
xlist = [int(i) for i in input().split()]

def pairwise(iterable):
    "s -> (s0,s1), (s1,s2), (s2, s3), ..."
    a, b = itertools.tee(iterable)
    next(b, None)
    return zip(a, b)
  
def calc_energy(path):
  ret = 0
  k = 0
  for pair in pairwise(path):
    ret += (k + 1) ** 2 * abs(pair[0] - pair[1])
    ret += X
    if pair[1] == 0:
      k = 0
    else:
      k += 1
  return ret

def movepath(cur, last):
  if not last:
    yield cur
  else:
    if cur[-1] == 0:
      for i in last:
        newlast = copy.copy(last)
        for ret in movepath(cur + [i], newlast):
          yield ret
    else:
      newlast = copy.copy(last)
      newlast.remove(cur[-1])
      for i in [0] + newlast:
       	for ret in movepath(cur + [i], newlast):
          yield ret

          
print(min(calc_energy(path) for path in movepath([0], xlist)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

cnt = 0
for i in a:
    if x >= i:
        cnt = cnt + 1
    else:
        break
    x = x - i

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

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

Submission status: Wrong Answer

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

for i in range(len(children)):
    x-=children[i]
    if x<0:
        print(i)
        exit()

print(N)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    n, x = map(int, input().split())
    aaa = list(map(int, input().split()))
    aaa.sort()
    ans = 0
    print(aaa)
    for a in aaa:
        if x < a:
            break
        ans += 1
        x -= a
#     else:
#         if x > 0:
#             ans -= 1
    print(ans)

Submission status: Wrong Answer

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

ans = 0
is_broken = False
for num in sorted(a):
    if num > k:
        break
        is_broken = True
    else:
        k -= num
        ans += 1
if k != 0 and ans >= 1 and not is_broken:
    ans -= 1
print(ans)

Submission status: Wrong Answer

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

ans = 0
is_broken = False
for num in sorted(a):
    if num > k:
        break
        is_broken = True
    else:
        k -= num
        ans += 1
if k != 0 and ans >= 1 and is_broken:
    ans -= 1
print(ans)

Submission status: Wrong Answer

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

ans = 0

for num in sorted(a):
    if num > k:
        break
    else:
        k -= num
        ans += 1
if k != 0 and ans >= 1:
    ans -= 1
print(ans)

Submission status: Wrong Answer

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

ans = 0

for num in sorted(a):
    if num > k:
        break
    else:
        k -= num
        ans += 1
if k != 0:
    ans -= 1
print(ans)

Submission status: Wrong Answer

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

ans = 0

for num in sorted(a):
    if num > k:
        break
    else:
        k -= num
        ans += 1
print(ans)

Submission status: Wrong Answer

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

a_list = [int(v) for v in input().split()]
a_list.sort()

person = 0

break_flag = False

for a in a_list[:-1]:
    if a <= x:
        x -= a
        person += 1
    else:
        break_flag=True
        break
  
if not break_flag:
    if x == a_list[-1]:
        person += 1

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = map(int, input().split())
arr = sorted(a)
ptr = 0
cnt = 0
if sum(a) == x:
	print(N)
else:
	while ptr < N and x >= arr[ptr]:
		cnt += 1
		x -= arr[ptr]
		ptr += 1
		
	print(cnt if x == 0 else max(0, cnt-1))

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = map(int, input().split())
arr = sorted(a)
ptr = 0
cnt = 0
while ptr < N and x >= arr[ptr]:
	cnt += 1
	x -= arr[ptr]
	ptr += 1
	
print(cnt if x == 0 else max(0, cnt-1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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


print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
ax = list(map(int,input().split()))
count = 0
for i in ax:
    if i<=x:
        count+=1
        x -= i
print(count)

Submission status: Wrong Answer

Solution code:
count = 0
N,x = map(int,input().split())
ax = list(map(int,input().split()))
for i in ax:
    if i<=x:
        count+=1
        x -= i
print(count)

Submission status: Wrong Answer

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

A.sort()
ct = 0
for i in range(n):
    if ct+A[i]>x:
        break
    ct+=A[i]
print(i)

Submission status: Wrong Answer

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

A.sort()
ct = 0
for i in range(n):
    if x>=A[i]:
        ct+=1
        x -= A[i]
    else:
        break
if x!=0 and i==n:
    ct-=1
print(ct)

Submission status: Wrong Answer

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

A.sort()
ct = 0
for i in range(n):
    if x>=A[i]:
        ct+=1
        x -= A[i]
    else:
        break
if x!=0 and i==n-1:
    ct-=1
print(ct)

Submission status: Wrong Answer

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

A.sort()
ct = 0
for i in range(n):
    if x>=A[i]:
        ct+=1
        x -= A[i]
if x!=0:
    ct-=1
print(ct)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
tmp1 = list(map(int, input().split()))
N = tmp1[0]
x = tmp1[1]
a = np.array(list(map(int, input().split())))
a = np.sort(a)
sum_candy = 0
for i in range(N-1):
  sum_candy += a[i]
  if sum_candy > x:
    break
print(i)

Submission status: Wrong Answer

Solution code:
import numpy as np
tmp1 = list(map(int, input().split()))
N = tmp1[0]
x = tmp1[1]
a = np.array(list(map(int, input().split())))
a = np.sort(a)
sum_candy = 0
for i in range(N):
  sum_candy += a[i]
  if sum_candy > x:
    break
if i == N - 1:
  print(i+1)
else:
  print(i)

Submission status: Wrong Answer

Solution code:
import numpy as np
tmp1 = list(map(int, input().split()))
N = tmp1[0]
x = tmp1[1]
a = np.array(list(map(int, input().split())))
a = np.sort(a)
sum_candy = 0
if a.sum() == x:
  print(N)
for i in range(N):
  sum_candy += a[i]
  if sum_candy > x:
    break
print(i)

Submission status: Wrong Answer

Solution code:
import numpy as np
tmp1 = list(map(int, input().split()))
N = tmp1[0]
x = tmp1[1]
a = np.array(list(map(int, input().split())))
a = np.sort(a)
sum_candy = 0
for i in range(N):
  sum_candy += a[i]
  if sum_candy > x:
    break
print(i)

Submission status: Wrong Answer

Solution code:
import numpy as np
tmp1 = list(map(int, input().split()))
N = tmp1[0]
x = tmp1[1]
a = np.array(list(map(int, input().split())))
a = np.sort(a)
count = 0
for i in range(N):
  if a[i] > x:
    break
  x -= a[i]
  if x < 0:
    count -= 1
    break
  count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
tmp1 = list(map(int, input().split()))
N = tmp1[0]
x = tmp1[1]
a = np.array(list(map(int, input().split())))
a = np.sort(a)
count = 0
for i in range(N):
  if a[i] > x:
    break
  x -= a[i]
  if x < 0:
    break
  count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
tmp1 = list(map(int, input().split()))
N = tmp1[0]
x = tmp1[1]
a = np.array(list(map(int, input().split())))
a = np.sort(a)
count = 0
for i in range(N):
  if a[i] > x or x == 0:
    break
  x -= a[i]
  count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
tmp1 = list(map(int, input().split()))
N = tmp1[0]
x = tmp1[1]
a = np.array(list(map(int, input().split())))
a = np.sort(a)
count = 0
for i in range(N):
  if a[i] > x:
    break
  x -= a[i]
  count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
tmp1 = list(map(int, input().split()))
N = tmp1[0]
x = tmp1[1]
a = np.array(list(map(int, input().split())))
a = np.sort(a)
count = 0
for i in range(N):
  if a[i] < x:
    break
  x -= a[i]
  count += 1
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
tmp1 = list(map(int, input().split()))
N = tmp1[0]
x = tmp1[1]
a = np.array(list(map(int, input().split())))
a = np.sort(a)
count = 0
for i in range(N):
  x -= a[i]
  if x < 0:
    if count != 0:
      count -= 1
    break
  else:
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
tmp1 = list(map(int, input().split()))
N = tmp1[0]
x = tmp1[1]
a = np.array(list(map(int, input().split())))
a = np.sort(a)
count = 0
for i in range(N):
  x -= a[i]
  if x == 0:
    count += 1
    break
  elif x < 0:
    if count != 0:
    	count -= 1
    break
  else:
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
tmp1 = list(map(int, input().split()))
N = tmp1[0]
x = tmp1[1]
a = np.array(list(map(int, input().split())))
a = np.sort(a)
count = 0
for i in range(N):
  x -= a[i]
  if x < 0:
    break
  else:
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
a = list(map(int,input().split()))
count = 0
for i in range(N):
    if(a[i]<=x):
        count+=1
        x-=a[i]
        
if(x>0 and count != 0):
    print(count-1)
else:
    print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
line = input().split()
N = int(line[0])
x = int(line[1])
ans = 0

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

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

Submission status: Wrong Answer

Solution code:
line = input().split()
N = int(line[0])
x = int(line[1])
ans = 0

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
line = input().split()
N = int(line[0])
x = int(line[1])
ans = 0

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

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

Submission status: Wrong Answer

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

a = sorted(a)

ans = 0
temp = x

while ans < n:
    temp -= a[ans]
    ans += 1
    if temp == 0:
        break
    elif temp < 0:
        ans -= 1
        break

print(ans)

Submission status: Wrong Answer

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

ret = 0
for a in A:
    if x < a:
        break
    ret += 1
    x -= a

print(ret if x == 0 else max(0, ret - 1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(n):
    x = x - li[i]
    if x < 0:
        print(i)
        break
else:
    print(n)

Submission status: Wrong Answer

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

a.sort()
ans = 0

for i, v in enumerate(a):
    if x == v or (i != N - 1 and x >= v):
        ans += 1
    #
#

print(ans)

Submission status: Wrong Answer

Solution code:
hito, ame = map(int, input().split())
NeedAme = list(map(int, input().split()))
NeedAme.sort()

ans = 0
total = 0
for n in NeedAme:
    if total + n <= ame:
        ans += 1
        total += n
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
#agc027a
import sys

n,x=map(int,raw_input().split())
a=map(int,raw_input().split())
a.sort()
res=x
for i in xrange(n):
 res-=a[i]
 if res<=0:
  if a[0]>x:
   print 0
  else:
   print i+1
  sys.exit()
print n-1

Submission status: Wrong Answer

Solution code:
import numpy as np

n,X = map(int,input().split())
xs = np.array(list(map(int,input().split())))
cumsumx =np.insert(np.cumsum(xs),0,0)

print(0)

Submission status: Wrong Answer

Solution code:
import numpy as np

n,X = map(int,input().split())
xs = np.array(list(map(int,input().split())))
cumsumx =np.insert(np.cumsum(xs),0,0)

def energy(k):
    nok = n//k
    acm = (n+k)*X
    for i in range(1,nok+1):
        relsum = cumsumx[-(i-1)*k-1] - cumsumx[-i*k-1]
        if i == 1:
            acm += 5*relsum
        else:
            acm += (2*i+1)*relsum
    relsum = cumsumx[-nok*k-1]
    acm += (2*(nok+1)+1)*relsum
    return(acm)

ans = -1
for j in range (1,n):
    tmp = energy(j)
    if tmp < ans or ans == -1:
        ans =tmp

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def solve(N, x, a_list):
    if sum(a_list) == x:
        return N
    sorted(a_list)
    happy_no = 0
    for a in a_list:
        if x < a:
            return happy_no
        happy_no += 1
        x -= a
    return N - 1

if __name__ == '__main__':
    (N, x) = (int(_) for _ in input().split())
    a_list = [int(a) for a in input().split()]
    print(solve(N, x, a_list))

Submission status: Wrong Answer

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

left=0
right=0
s=a[0]
answer = 0
while True:
    if left >= N or right >= N:
        break
    if s <= x:
        if s == x:
            answer = max(answer,right-left+1)
        if s < x:
            if right-left < N-1:
                answer = max(answer,right-left+1)
        right += 1
        if right < N:
            s += a[right]
        continue
    if s > x:
        s -= a[left]
        left += 1
        continue
print(answer)

Submission status: Wrong Answer

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

left=0
right=0
s=a[0]
answer = 0
while True:
    if left >= N or right >= N:
        break
    if s <= x:
        if s == x:
            answer = max(answer,right-left+1)
        if s < x:
            if right-left < N-1:
                answer = max(answer,right-left+1)
            else:
                answer = max(answer,right-left)
        right += 1
        if right < N:
            s += a[right]
        continue
    if s > x:
        s -= a[left]
        left += 1
        continue
print(answer)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline
n, x = map(int, input().split())
a_list = list(map(int, input().split()))
a_list.sort()
cnt = 0
for a in a_list:
    if x >= a:
        cnt += 1
        x -= a
if x > 0:
    cnt -= 1
print(max(cnt, 0))

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline
n, x = map(int, input().split())
a_list = list(map(int, input().split()))
a_list.sort()
cnt = 0
for i in range(n):
    if x < a_list[i]:
        break
    else:
        cnt += 1
        x -= a_list[i]
if x > 0:
    cnt -= 1
print(max(cnt, 0))

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in input().split(' ')]
import sys
from collections import defaultdict
sys.setrecursionlimit(100000)

s = input().strip()
ds = [defaultdict(set), defaultdict(set)]
starts = set()
for ll in sys.stdin:
    i, j = ll.strip().split(' ')
    i, j = int(i)-1, int(j)-1
    ds[0 if s[i] == s[j] else 1][str(0 if s[i] == s[j] else 1) + str(i)].add(str(1 if s[i] == s[j] else 0) + str(j))
    ds[0 if s[i] == s[j] else 1][str(0 if s[i] == s[j] else 1) + str(j)].add(str(1 if s[i] == s[j] else 0) + str(i))
    if s[i] == 'A' and s[j] == 'A':
        starts.add(str(0)+str(i))


checked = set()

path = set()
#path = []

def walk(i, depth):
    dd = ds[depth]
    checked.add(i)
    if len(dd[i]) == 0:
        return False
    r = False
    for item in dd[i]:
        if item in path:
            return True
        if item not in checked:
            path.add(item)
#            path.append(item)
            r = r or walk(item, (depth+1) % 2)
            path.remove(item)
#            path.pop()
    return r

result = False
for item in starts:
    if item not in checked:
        path.add(item)
#        path.append(item)
        result = result or walk(item, 0)
        path.remove(item)
#        path.pop()
if result:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    """
    2 <= N <= 100
    1 <= ai,x <= 10^9
    """
    N, x = map(int, input().split())
    *a, = map(int, input().split())

    ans = 0
    for _a in sorted(a):
        if _a <= x:
            ans += 1
            x -= _a

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, V = list(map(int, input().split()))
C = list(map(int, input().split()))
N = len(C)

if sum(C)==V:
  print(N)
else:
  cnt = 0
  for c in sorted(C):
    if V-c>0:
      cnt += 1
      V -= c
    else:
      break
  print(min(cnt, N-1))

Submission status: Wrong Answer

Solution code:
N, V = list(map(int, input().split()))
C = filter(lambda x: x<=V, map(int, input().split()))
C = list(C)
N = len(C)
 
cnt = 0
for c in sorted(C):
  if V>0 and V-c>=0:
    cnt += 1
    V -= c
  if V<=0:
    break
print(cnt) if V<=0 else print(cnt-1)

Submission status: Wrong Answer

Solution code:
N, V = list(map(int, input().split()))
C = filter(lambda x: x<=V, map(int, input().split()))
C = list(C)
N = len(C)

cnt = 0
for c in sorted(C):
  if V>0 and V-c>=0:
    cnt += 1
    V -= c
  if V<=0:
    break
print(cnt)

Submission status: Wrong Answer

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

a.sort()

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

print(ans)

Submission status: Wrong Answer

Solution code:
def cda(N, x, a, count):
    if N == 0:
        return count
    s = sorted(a)
    if x >= s[0]:
        return cda(N - 1, x - s[0], s[1:], count + 1)
    else:
        return count

def agc027a():
    N, x = (int(s) for s in input().split(" "))
    a = [int(s) for s in input().split(" ")]
    answer = cda(N, x, a, 0)
    print(answer)

def main():
    agc027a()

main()

Submission status: Wrong Answer

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

ans=0

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

if cage[0]>x:
    ans=0

print(ans)

Submission status: Wrong Answer

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

ans=0

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

if cage[0]>x:
    ans=0
if x>0:
    ans = ans - 1
print(ans)

Submission status: Wrong Answer

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

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

if x > 0:
    ans -= 1

print(max(0,ans))

Submission status: Wrong Answer

Solution code:
def cda(N, x, a, count):
    if N == 0:
        return count
    s = sorted(a)
    if x >= s[0]:
        return cda(N - 1, x - s[0], s[1:], count + 1)
    else:
        return count

def arc027a():
    N, x = (int(s) for s in input().split(" "))
    a = [int(s) for s in input().split(" ")]
    print(N, x, a)
    answer = cda(N, x, a, 0)
    print(answer)

def main():
    arc027a()

main()

Submission status: Wrong Answer

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

ans=0

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

if cage[0]>x:
    ans=0

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
def cda(N, x, a, count):
    if N == 0:
        return count
    s = sorted(a)
    if x >= s[0]:
        return cda(N - 1, x - s[0], s[1:], count + 1)
    else:
        return count

def arc027a():
    N, x = (int(s) for s in next(stdin).split(" "))
    a = [int(s) for s in next(stdin).split(" ")]
    print(N, x, a)
    answer = cda(N, x, a, 0)
    print(answer)

def main():
    arc027a()

main()

Submission status: Wrong Answer

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

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
if b[-1] > X:
    c -= 1
print(c)

Submission status: Wrong Answer

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

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

if cage[0]>x:
    ans=0
if x != 0:
    ans -= 1
print(ans)

Submission status: Wrong Answer

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

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:
  if sum<=n:
    print(n)
  else:
    print(n-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
x_tmp = x
for i, Ai in enumerate(sorted(A)):
    x_tmp -= Ai
    if x_tmp >= 0: ans += 1
    else: break

if sum(A) == x: print(N)
elif x_tmp + Ai == 0: print(max(0, ans))
else: print(max(0, ans - 1))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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:
  if sum==n:
    print(n)
  else:
    print(n-1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Sep 15 23:36:39 2018

@author: Yuki
"""

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

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

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:
  if sum==n:
    print(n)
  else:
    print(n-1)

Submission status: Wrong Answer

Solution code:

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

A = sorted(A)
res = 0
for a in A:
    x -= a
    if x <= 0:
        break
    else:
        res += 1
print(res)