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:
n, x = map(int, input().split())
A = list(map(int, input().split()))

A.sort()
RA = []
q = 0
for i in range(n):
    q += A[i]
    RA.append(q)

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/agc027/tasks/agc027_a


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

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

    if x != 0:
        count = max(0, count - 1)

    print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import bisect

N, x = map(int, input().split())
A = list(map(int, input().split()))
S = [0] * (N + 1)
A.sort()

for i, a in enumerate(A):
    S[i + 1] = S[i] + a

if S[-1] > x:
    print(N - 1)
elif S[-1] == x:
    print(N)
else:
    print(bisect.bisect_right(S, x))

Submission status: Wrong Answer

Solution code:
import bisect

N, x = map(int, input().split())
A = list(map(int, input().split()))
S = [0] * (N + 1)
A.sort()

for i, a in enumerate(A):
    S[i + 1] = S[i] + a

print(bisect.bisect_left(S, x))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
N,x=[int(x) for x in stdin.readline().rstrip().split()]
data=[int(x) for x in stdin.readline().rstrip().split()]
data=sorted(data)
ans=0
if data[0] < x:
    print(0)
else:
    for i in data:
        x=x-i
        if x <= 0:
            break
        ans+=1
    if x!=0 and ans !=1:
        ans-=1
    print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N,x=[int(x) for x in stdin.readline().rstrip().split()]
data=[int(x) for x in stdin.readline().rstrip().split()]
data=sorted(data)
ans=0
if data[0] > x:
    print(0)
else:
    for i in data:
        x=x-i
        if x < 0:
            break
        ans+=1
    if x!=0 and ans !=1:
        ans-=1
    print(ans)

Submission status: Wrong Answer

Solution code:

a=raw_input();
lt=a.split(' ')
n=int(lt[0])
x=int(lt[1])
b=raw_input()
lt=b.split(' ')
ar=[]
for i in range(0,n):
	ar.append(int(lt[i]))

ar.sort()
v=0
for i in range(0,n):
	if x>=ar[i]:
		v+=1
	else:
		break
	x-=ar[i];
if x>0 and v>0:
	v-=1
print(v)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_right
n,x=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
S=list(accumulate(A))
i=bisect_right(S,x)
print(i if i!=n else n-1)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from bisect import bisect_right
n,x=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
S=list(accumulate(A))
i=bisect_right(S,x)
if i==0:
    print(0)
elif S[i-1]==x:
    print(i)
else:
    print(i-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

N, x = map(int, input().split())
aList = map(int, input().split())
sortedAList = sorted(aList)

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

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

Submission status: Wrong Answer

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

else:
    print(0)
    exit()

if x > 0:
    print(ans-1)
else:
    print(ans)

Submission status: Wrong Answer

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

else:
    print(0)
    exit()


if x > 0:
    print(ans-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
lst=sorted(list(map(int,input().split())))
ans=0
for i in range(1,n+1):
    if sum(lst[:i]) <= x:
        ans = len(lst[:i])
print(ans)

Submission status: Wrong Answer

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

else:
    print(0)
    exit()


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

if x > 0:
    print(ans-1)
else:
    print(ans)

Submission status: Wrong Answer

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

a_list.sort()
ans = 0
for i in range(n):
  a = a_list[i]
  x = x - a
  if x < 0:
    break
  ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
nx = [int(i) for i in input().split()]
n = nx[0]
x = nx[1]
a = [int(i) for i in input().split()]
b =list(sorted(a))
s = 0
ans = 0
for i in range(n+1):
    if sum(b[:i])<=x:
        s = sum(b[:i])
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

A = sorted(A, reverse=True)

ans = N
sumA = sum(A)
if sumA == x:
    ans = N
else:
    ans = N-1
    for a in A[1:]:
        if sumA > x:
            sumA -= a
            ans -= 1
        else:
            break
print(ans)

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

A = sorted(A, reverse=True)

ans = N
sumA = sum(A)
for a in A:
    if sumA > x:
        sumA -= a
        ans -= 1
    else:
        break
print(ans)

Submission status: Wrong Answer

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

li.sort()

child = 0
candy = 0
for a in li:
    if candy + a > x:
        continue
    candy += a
    child += 1
    if candy == x:
        break
else:
    child -= 1

print(child)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a_sort = sorted(a)
ans = 0
for i in range(0,N):
	if x > sum(a_sort[:i:]):
		ans += 1
		
if ans == N and x > sum(a_sort):
	ans -= 1
if x < a_sort[0]:
	ans = 0
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


def ii():
    return int(input())


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


N, X = il()
A = sorted(il())
if X == sum(A):
    print(N)
    exit()
c = 0
for i in range(1, N + 1):
    if sum(A[:i]) <= X:
        c += 1
    else:
        break
if N == i:
    print(c - 1)
else:
    print(i - 1)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


def ii():
    return int(input())


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


N, X = il()
A = sorted(il())
if sum(A) == N:
    print(N)
    exit()
c = 0
for i in range(N):
    if sum(A[:i]) <= X:
        c = i
print(c if c != N else N - 1)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


def ii():
    return int(input())


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


N, X = il()
A = sorted(il())
if sum(A) == N:
    print(N)
    exit()
c = 0
for i in range(N):
    if sum(A[:i]) <= X:
        c = i
print(c)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


def ii():
    return int(input())


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


N, X = il()
A = sorted(il())
c = 0
for i in range(N + 1):
    if sum(A[:i]) <= X:
        c = i
print(c)

Submission status: Wrong Answer

Solution code:
import sys
import itertools

lines = sys.stdin.readlines()

for n, line in enumerate(lines):
  if not n:
    N, x = [int(_) for _ in line.strip().split(' ')]
    continue
  children = sorted([int(_) for _ in line.strip().split(' ')])
  break
  
child_max = max(children)
coef_pattern = [_ for _ in range(x // child_max + 1)]
child_id = [_ for _ in range(len(children))]
pattern = list(itertools.product(coef_pattern, child_id))
all_pattern = list(itertools.permutations(pattern))
#print(all_pattern)
max_cnt = 0
for ap in all_pattern:
  total = 0
  cnt = 0
  #print('ap:{}'.format(ap))
  log = []
  given_child = []
  for p in ap:
    #print('p[1]:{}, p[0]:{}'.format(p[1], p[0]))
    total += children[p[1]] * p[0]
    if not p[0] == 0 and not p[1] in given_child:
      cnt += 1
      #log.append('total:{}, p[1]:{}, p[0]:{}'.format(total, p[1], p[0]))
      given_child.append(p[1])
    #print('total:{}'.format(total))
    if total == x:
      if max_cnt < cnt:
        max_cnt = cnt
        #print(log)
print(max_cnt)

Submission status: Wrong Answer

Solution code:
#Begginer027

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

A.sort()
candy = 0
ans = 0
for i in A:
    candy += i
    if candy <= x:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
#Begginer027

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

A.sort(reverse=True)
candy = 0
ans = 0
for i in A:
    candy += i
    if candy <= x:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
num = a[0]
i = 0
if sum(a) > x:
    while num <= x:
        num += a[i]
        i += 1
    print(i)
elif sum(a) == x:
    print(N)
else:
    print(N-1)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
count = 0
if sum(a) > x:
    num = a[0]
    i = 0
    while num <= x:
        num += a[i]
        i += 1
    print(i)
elif sum(a) == x:
    print(N)
else:
    print(N-1)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
count = 0
if sum(a) >= x:
    num = 0
    i = 0
    while num > x:
        i += 1
        num += a[i]
    print(i)
elif sum(a) == x:
    print(N)
else:
    print(N-1)

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

Submission status: Wrong Answer

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

A.sort()
count = 0

for i in range(n):
    if x >= A[i]:
        x -= A[i]
        count += 1

if x != 0 and count != 0:
    count -= 1

print(count)

Submission status: Wrong Answer

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

A.sort(reverse=True)
count = 0

for i in range(n):
    if x >= A[i]:
        x -= A[i]
        count += 1

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 = sorted(a)[::-1]
res = 0
p = 0
for i in a:
    x -= i
    if x < 0:
        x += i
        break
    res += 1
    p += 1
else:
    if x > 0:
        res -= 1
#print(p, a[p:])
print(res + (x in a[p:]))

Submission status: Wrong Answer

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

candy_num.sort(reverse=True)

sum_want = 0
num_child = 0

for i in candy_num:
    sum_want += i
    num_child += 1
    if not sum_want <= x:
        break

if num_child == N:
    print(N-1)
else:
    print(num_child)

Submission status: Wrong Answer

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

li.sort()
ans = 0

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

Submission status: Wrong Answer

Solution code:
temp = input().rstrip().split(" ")
N = int(temp[0])
X = int(temp[1])
list = input().rstrip().split(" ")
list.sort()
print(list)
c = 0
for i in range(N):
    X = X - int(list[i])
    if X >= 0:
       c += 1
    else:
        break
if X <= 0:
    print(c)
elif X > 0:
    print(c-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

cnt=0
for a in A:
    if x < a or x <= 0:
        break
    else:
        x-=a
        cnt+=1
        
if 0 < x and 0 < cnt:
    cnt-=1

print(cnt)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-

s = raw_input()
n, x =  [int(i) for i in s.split()]

aa = raw_input()
a = [int(i) for i in aa.split()]

a = sorted(a)
count = 0
total = 0
for i in a:
    total += i
    if total > x:
        break
    count += 1
print count

Submission status: Wrong Answer

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

n, x = int(n), int(x)
a = sorted([int(i) for i in a])

s = x
ret = 0
for i in a:
    if s >= i:
        ret += 1
        s -= i
        n -= 1

if ret and s:
    ret -= 1

print(ret)

Submission status: Wrong Answer

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

n, x = int(n), int(x)
a = sorted([int(i) for i in a])

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

if s and ret:
    ret -= 1

print(ret)

Submission status: Wrong Answer

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

n, x = int(n), int(x)
a = sorted([int(i) for i in a])

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

print(ret)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-

s = raw_input()
n, x =  [int(i) for i in s.split()]

aa = raw_input()
a = [int(i) for i in aa.split()]

a = sorted(a)
count = 0
total = 0
for i in a:
    total += i
    if total == x:
        count += 1
        break
    if total > x:
        break
    count += 1
print count

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-

s = raw_input()
n, x =  [int(i) for i in s.split()]

aa = raw_input()
a = [int(i) for i in aa.split()]

a = sorted(a)
count = 0
total = 0
for i in a:
    total += i
    if total > x:
        break
    count += 1
print count
#17024977 | shenweiqiang's solution for [AtCoder-4375] [Problem E]

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())
List = list(map(int, input().split()))
Sorted = sorted(List)
A = B = 0
if sum(List) == x:
    print(N)
elif sum(List) < x:
    print(N-1)
else:
    for i in Sorted:
        B += 1
        A += i 
        if A == x:
            print(B)
            break
        else:
            print(B-1)
            break

Submission status: Wrong Answer

Solution code:
N,x=map(int,input().split())
Children=list(map(int,input().split()))
Children.sort(key=lambda x:x)
n=0
S=0
while n<=N-1:
  S+=Children[n]
  if S<x:
    n+=1
  elif S==x:
    n+=1
    break
  elif S>x:
    break
if S<x:
  n=-1
print(n)

Submission status: Wrong Answer

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

for i in range(a[0]):
  if i == 0 and a[1] < c[0]:
    print(0)
    break
  a[1] -= c[i]
  if a[1] <= 0:
    print(i+1)
    break
else:
  if a[1] == 0:
    print(a[0])
  else:
    print(a[0]-1)

Submission status: Wrong Answer

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

c = sorted(b)

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

Submission status: Wrong Answer

Solution code:

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

a = 0
i = 0

if list[0] > x:
    print(0)

elif x > sum(list):
    print(n-1)

else:
    while x > 0 and x >= list[i]:
        x -= list[i]
        i += 1
        a += 1
        if i == n:
            break

    print(a)

Submission status: Wrong Answer

Solution code:
# AtCorder-Candy Distribution Again

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

a = 0
i = 0
list.sort()

if x < list[0]:
    print(0)

elif x >= list[0]:

    while x >= list[i] and x > 0:
        x -= list[i]
        if i == n-1:
            break

        a += 1
        if i < n-1 and x < list[i+1]:
            break
        i += 1

    if x > list[n-1]:
        a = n-1

    print(a)

Submission status: Wrong Answer

Solution code:
# AtCorder-Candy Distribution Again

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

a = 0
i = 0
list.sort()

if x < list[0]:
    print(0)

elif x >= list[0]:

    while x >= list[i] and x > 0:
        x -= list[i]
        a += 1
        if i < n-1 and x < list[i+1]:
            break
        if i == n-1:
            a = n
            break
        i += 1

    print(a)

Submission status: Wrong Answer

Solution code:
# AtCorder-Candy Distribution Again

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

a = 0
i = 0
list.sort()

if x < list[0]:
    print(0)

elif x >= list[0]:

    while x > 0 and x >= list[i]:
        x -= list[i]
        a += 1
        if i < n-1 and x < list[i+1]:
            break
        if i == n-1:
            a = n
            break
        i += 1

    print(a)

Submission status: Wrong Answer

Solution code:
# AtCorder-Candy Distribution Again

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

a = 0
list.sort()
i = 0

if x < list[0]:
    print(0)

elif x >= list[0]:
    # x -= list[i]
    # print(x)
    while x >= 0:
        x -= list[i]
        a += 1
        i += 1
        if i == n-1 or x == 0:
            a += 1
            break
    # print(x)
    print(a)


    # return print(a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a.sort()
ans = 0

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

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

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# A
n,x = list(map(int, input().split()))
a = list(map(int, input().split()))
num = 0
for ai in sorted(a):
    if ai<=x:
        num+=1
        x-=ai
    else:
        break
if num>0 and x>0:
    num-=1
print(num)

Submission status: Wrong Answer

Solution code:
# A
n,x = list(map(int, input().split()))
a = list(map(int, input().split()))
num = 0
for ai in sorted(a):
    if ai<x:
        num+=1
        x-=ai
    else:
        break
if x>0:
    num-=1
print(num)

Submission status: Wrong Answer

Solution code:
def main():

    N, x = list(map(int, input().split()))
    a = list(map(int, input().split()))
 
    b = sorted(a)
 
    ans = 0
    total = 0
 
    for i in range(len(b)):
        if total + b[i] <= x:
            ans += 1
            total += b[i]


    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():

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


    print(ans)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = map(int, input().split())
a_sorted = sorted(a)
if sum(a_sorted) <= x:
  print(N)
else:
  i = 0
  a_sum = 0
  while a_sum <= x:
    a_sum += a_sorted[i]
    i += 1
  print(i - 1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

a.sort()

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

Submission status: Wrong Answer

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

a.sort()

count = 0
for a_i in a:
    x -= a_i
    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()

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

Submission status: Wrong Answer

Solution code:
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:
        print(i+1)
        exit()
print(n)

Submission status: Wrong Answer

Solution code:
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:
        print(i)
        exit()
print(n)

Submission status: Wrong Answer

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

for i, a_i in enumerate(sorted(a)):
    x -= a_i
    if x <= 0:
        print(i)
        exit()
print(n)

Submission status: Wrong Answer

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

for i, a_i in enumerate(sorted(a)):
    x -= a_i
    if x < 0:
        print(i)
        exit()
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 in a:
    if i<=x:
        x-=i
        ans+=1
if x:
    ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
import copy
import itertools
import sys

sys.setrecursionlimit(10**8)

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)))