TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: You are given positive integers N and M.  How many sequences a of length N consisting of positive integers satisfy a_1 \times a_2 \times ... \times a_N = M? Find the count modulo 10^9+7.  Here, two sequences a' and a'' are considered different when there exists some i such that a_i' \neq a_i''.

Submission attempts (in order):
import math

N, M = map(int, input().split())
yakusu = dict()
sqrt_M = int(math.sqrt(M))
for i in range(2, sqrt_M + 1):
    count = 0
    while M % i == 0:
        count += 1
        M //= i
    if count > 0:
        yakusu[i] = count
if M > 1:
    yakusu[M] = 1


def nCr(n, r):
    if r > n - r:
        return nCr(n, n - r)
    ans = 1
    for i in range(n, n-r, -1):
        ans *= i
    for i in range(1, r+1):
        ans //= i
    return ans


ans = 1
MOD = 10 ** 9 + 7
for n in yakusu.values():
    print(n)
    ans *= nCr(n + N - 1, N - 1)
    ans %= MOD

print(ans)


import math

N, M = map(int, input().split())
yakusu = dict()
sqrt_M = int(math.sqrt(M))
for i in range(2, sqrt_M + 1):
    count = 0
    while M % i == 0:
        count += 1
        M //= i
    if count > 0:
        yakusu[i] = count
if M > 1:
    yakusu[M] = 1


def nCr(n, r):
    if r > n - r:
        return nCr(n, n - r)
    ans = 1
    for i in range(n, n-r, -1):
        ans *= i
    for i in range(1, r+1):
        ans //= i
    return ans


ans = 1
MOD = 10 ** 9 + 7
for n in yakusu.values():
    ans *= nCr(n + N - 1, N - 1)
    ans %= MOD

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: You are given positive integers N and M.  How many sequences a of length N consisting of positive integers satisfy a_1 \times a_2 \times ... \times a_N = M? Find the count modulo 10^9+7.  Here, two sequences a' and a'' are considered different when there exists some i such that a_i' \neq a_i''.

Submission attempts (in order):
    if M == 1:
        return 1

    def prime_factorization_power_list(n):
        i = 2
        table = {}
        while i**2 <= n:
            table[i] = 0
            while n % i == 0:
                table[i] += 1
                n //= i
            if table[i] == 0:
                table.pop(i)
            i += 1
        if n > 1:
            table[n] = 1
        return table

    MOD = 10**9 + 7
    prime_m = prime_factorization_power_list(M)
    b_max = max(prime_m.values())  
    
    factorial = [1] * (b_max + N)  
    for k in range(1, b_max + N - 1):
        factorial[k + 1] = (factorial[k] * (k + 1)) % MOD
    
    fact_inv = [1] * (b_max + N)
    fact_inv[b_max + N - 1] = pow(factorial[b_max + N - 1], MOD - 2, MOD)
    for k in range(b_max + N - 1, 0, -1):
        fact_inv[k - 1] = (fact_inv[k] * k) % MOD

    def nCr(n, r, M):
        if n < 0 or r < 0 or n < r:
            return 0
        else:
            return (factorial[n] * fact_inv[r] * fact_inv[n - r]) % M

    ans = 1
    for b in prime_m.values():
        ans = (ans * nCr(b + N - 1, b, MOD)) % MOD

    return ans

N, M = [int(i) for i in input().split()]
print(d_factorization(N, M))

def d_factorization(MOD=10**9 + 7):
    N, M = [int(i) for i in input().split()]

    def prime_factorization_dict(n):
        if n == 1:
            return {2: 0}  
        i, table = 2, {}
        while i**2 <= n:
            table[i] = 0
            while n % i == 0:
                table[i] += 1
                n //= i
            if table[i] == 0:
                table.pop(i)
            i += 1
        if n > 1:
            table[n] = 1
        return table

    class Combination(object):
        
        __slots__ = ['mod', 'factorial', 'inverse']

        def __init__(self, max_val_arg: int = 10**6, mod: int = 10**9 + 7):
            fac, inv = [1], []
            fac_append, inv_append = fac.append, inv.append

            for i in range(1, max_val_arg + 1):
                fac_append(fac[-1] * i % mod)

            inv_append(pow(fac[-1], mod - 2, mod))

            for i in range(max_val_arg, 0, -1):
                inv_append((inv[-1] * i) % mod)

            self.mod, self.factorial, self.inverse = mod, fac, inv[::-1]

        def combination(self, n, r):
            if n < 0 or r < 0 or n < r:
                return 0
            return self.factorial[n] * self.inverse[r] * self.inverse[n - r] % self.mod

        def combination_with_repetition(self, n, r):
            return self.combination(n + r - 1, r)

    prime_m = prime_factorization_dict(M)
    h = Combination(max(prime_m.values()) + N - 1).combination_with_repetition
    ans = 1
    for b in prime_m.values():
        ans = (ans * h(N, b)) % MOD
    return ans

print(d_factorization())

Verdicts: Runtime Error

Accepted
Problem: You are given positive integers N and M.  How many sequences a of length N consisting of positive integers satisfy a_1 \times a_2 \times ... \times a_N = M? Find the count modulo 10^9+7.  Here, two sequences a' and a'' are considered different when there exists some i such that a_i' \neq a_i''.

Submission attempts (in order):
import collections
import math
n,m=map(int,input().split())
flag=0
P=[]
p=m
while flag==0:
  cur=p
  for i in range(2,int(p**0.5)+1):
    if p%if==0:
      P.append(i)
      p//=i
      break
  if p==cur:
    P.append(p)
    flag=1
c=collections.Counter(P)
Primes=set(P)
def f(i):
  return math.factorial(i)
def fn(i):
  return f(n+i-1)//(f(n-1)*f(i))
ans=1
for p in Primes:
  ans*=fn(c[p])
print(ans) 

import sys
input=lambda: sys.stdin.readline().rstrip()
mod=10**9+7
n,m=map(int,input().split())
n_max=2*(10**5+1)
F,FI=[0]*(n_max+1),[0]*(n_max+1)
F[0],FI[0]=1,1
for i in range(n_max):
  F[i+1]=(F[i]*(i+1))%mod
FI[n_max-1]=pow(F[n_max-1],mod-2,mod)
for i in reversed(range(n_max-1)):
  FI[i]=(FI[i+1]*(i+1))%mod
def comb(x,y):
  return (F[x]*FI[x-y]*FI[y])%mod

pf={}
for i in range(2,int(m**0.5)+1):
  while m%i==0:
    pf[i]=pf.get(i,0)+1
    m//=i
if m>1:
  pf[m]=1

ans=1
for k in pf.keys():
  ans=(ans*comb(n-1+pf[k],pf[k]))%mod
print(ans)

Verdicts: Runtime Error

Accepted
Problem: You are given positive integers N and M.  How many sequences a of length N consisting of positive integers satisfy a_1 \times a_2 \times ... \times a_N = M? Find the count modulo 10^9+7.  Here, two sequences a' and a'' are considered different when there exists some i such that a_i' \neq a_i''.

Submission attempts (in order):
N, M = map(int, input().split())
mod = int(1e+9 + 7)
a = mod - 2
ax = []
while a != 0:
  ax = [a%2] + ax[:]
  a //= 2
def inved(x):
  y = 1
  for i in range(len(ax)):
    if ax[i] == 1:
      y *= x
      y %= mod
    if i != len(ax) - 1:
      y *= y
      y %= mod
  return y

p, n = 2, M
L = []
dig = 1
while n != 1:
  i = 0
  while n % p == 0:
    n //= p
    dig *= p
    i += 1
  if i != 0:
    L.append([p, i])
  p += 1
  if p > int(M**(1/2)) and dig != M:
    if L != []:
      L.append([M//dig, 1])
    else:
      L.append([M, 1])
    break
print(L)
if M == 1:
  print(1)
else:
  prod = 1
  mm = max(x[1] for x in L)
  fact = [1]
  for i in range(N + mm - 1):
    fact.append((fact[i] * (i + 1)) % mod)
  invf = inved(fact[N - 1])
  for i in L:
    pad = (fact[N - 1 + i[1]] * inved(fact[i[1]]) * invf) % mod
    prod *= pad
    prod %= mod
  print(prod)

N, M = map(int, input().split())
mod = int(1e+9 + 7)
a = mod - 2
ax = []
while a != 0:
  ax = [a%2] + ax[:]
  a //= 2
def inved(x):
  y = 1
  for i in range(len(ax)):
    if ax[i] == 1:
      y *= x
      y %= mod
    if i != len(ax) - 1:
      y *= y
      y %= mod
  return y

p, n = 2, M
L = []
dig = 1
while n != 1:
  i = 0
  while n % p == 0:
    n //= p
    dig *= p
    i += 1
  if i != 0:
    L.append([p, i])
  p += 1
  if p > int(M**(1/2)) and dig != M:
    if L != []:
      L.append([M//dig, 1])
    else:
      L.append([M, 1])
    break

if M == 1:
  print(1)
else:
  prod = 1
  mm = max(x[1] for x in L)
  fact = [1]
  for i in range(N + mm - 1):
    fact.append((fact[i] * (i + 1)) % mod)
  invf = inved(fact[N - 1])
  for i in L:
    pad = (fact[N - 1 + i[1]] * inved(fact[i[1]]) * invf) % mod
    prod *= pad
    prod %= mod
  print(prod)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
count = 0
for i in range(N):
    x = x - a[i]
    if x >= 0:
        count += 1  

print(count)

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# -*- coding: utf-8 -*-
import sys
import itertools
import math
#w=input()
N, x=input().split()
N=int(N)
x=int(x)
#x=[]
#y=[]




#l=0
#t[0],x[0],y[0]=[0, 0, 0]


# t[i+1], x[i+1], y[i+1] = map(int, input().split())
child_i =  list(map(int, input().split()))
#w_len=len(w)
#w_list=list(w)
#print(len(w_list))
#print(w_list)
child_il=sorted(child_i)

i=0
j=0
for i in range(N):
 x=x-child_il[i]
 if x < 0:
    print(j)
    sys.exit()
 else:
     j=j+1

print(j)


# -*- coding: utf-8 -*-
import sys
import itertools
import math
#w=input()
N, x=input().split()
N=int(N)
x=int(x)
#x=[]
#y=[]




#l=0
#t[0],x[0],y[0]=[0, 0, 0]


# t[i+1], x[i+1], y[i+1] = map(int, input().split())
child_i =  list(map(int, input().split()))
#w_len=len(w)
#w_list=list(w)
#print(len(w_list))
#print(w_list)
child_il=sorted(child_i)

i=0
j=0
for i in range(N):
 x=x-child_il[i]
 if x < 0:
    print(j)
    sys.exit()
 elif i==N-1 and x!=0:
    break 
 else:
     j=j+1

print(j)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n,x=map(int,input().split())
l1=list(map(int,input().split()))
l1.sort()
ans=0
while len(l1)>0:
    t1=l1.pop(0)
    if x>=t1:
        x-=t1
        ans+=1
print (ans)

n,x=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
ans=ac=0
for i in l:
    ac+=i
    if x>=ac:
        ans+=1
if ac<x:
    ans-=1
print (ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
a.reverse()
ans=0
while x>0:
  if len(a)==0:
    break
  if a[-1]<=x:
    x-=a.pop()
    ans+=1
  else:
    break
print(ans)

n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
a.reverse()
ans=0
while x>0:
  if x==0:
    break
  elif len(a)==0:
    ans-=1
    break
  if a[-1]<=x:
    x-=a.pop()
    ans+=1
  else:
    break
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
b=a[0]
if b>x:c=0
else:c=1
for i in range(n):
  b=b+a[i]
  if b>x:
    break
  c+=1
if c>n:c=n
print(c)

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n, x = map(int, input().split())
a = [int(x) for x in input().split()]
a.sort()
ans = 0
for i in range(n):
  if a[i] <= x:
    ans += 1
    x -= a[i]
  else:
    break
print(ans)

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n, x = map(int, input().split())
a_l = list(map(int, input().split()))
a_l = sorted(a_l)
ans = 0
for a in a_l:
    x = x-a
    if x < 0:
        break
    ans += 1
print(ans)

n, x = map(int, input().split())
a_l = list(map(int, input().split()))
a_l = sorted(a_l)
ans = 0
for a in a_l:
    x = x-a
    if x < 0:
        break
    ans += 1
if x > 0:
    ans -= 1
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, x = map(int, input().split())
child_list = list(map(int, input().split()))

count = 0
for child in sorted(child_list):
  x -= child
  if x < 0:
    break
  count += 1


print(count)

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

count = 0
for child in sorted(child_list):
  x -= child
  if x < 0:
    break
  count += 1

count = N if count >= N else count
print(count)

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

count = 0
for i, child in enumerate(sorted(child_list)):
  x -= child
  if x < 0:
    break
  if (i == len(child_list) - 1) and x != 0:
    break
  count += 1

print(count)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, x = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
sum = 0
ans = 0
for i,a in enumerate(A):
    sum += a

    if sum == x:
        ans = i + 1
        break
    elif sum > x:
        break
    ans = i + 1


print(ans)


N, x = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
sum = 0
ans = 0
for i,a in enumerate(A):
    sum += a

    if sum == x:
        ans = i + 1
        break
    elif sum > x:
        break
    elif i + 1 == N and sum < x:
        ans = i
        break
    ans = i + 1


print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N,x=map(int,input().split())
count=0
c=list(map(int,input().split()))
c.sort()
for i in range(N):
	x=x-int(c[i])
	if x>=0:
		count+=1
print(count)

N,x=map(int,input().split())
count=0
c=list(map(int,input().split()))
c.sort()
for i in range(N):
	x=x-int(c[i])
	if x>=0:
		count+=1
if x>0:
	count=count-1
print(count)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
count=0

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

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

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

if x==a[-1]:
    count+=1
print(count)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
_=0
ans=0
for i in range(N):
    _+=a[i]
    if _ <= x:
        ans += 1
print(ans)
        


n,x=map(int,input().split())
a=list(map(int,input().split()))
A=0
for i in range(len(a)):
  A += a[i]
if A < x:
  print(n-1)
else:
  b=sorted(a)
  c=0
  ans=0
  for _ in range(len(a)):
    c += b[_]
    if c <= x:
      ans += 1
    else:
      break
  print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, X = map(int, input().split())
la = sorted(list(map(int, input().split())))

print(la)

if X < la[0]:
    print(0)
elif X > sum(la):
    print(N-1)
elif X == sum(la):
    print(N)
else:
    j = 0
    while X > 0:
        X = X - la[j]
        j += 1
    print(j)

N, X = map(int, input().split())
la = sorted(list(map(int, input().split())))

if X < la[0]:
    print(0)
elif X > sum(la):
    print(N-1)
elif X == sum(la):
    print(N)
else:
    j = 0
    while X > 0:
        X = X - la[j]
        j += 1
    if X < 0:
        print(j-1)
    else:
        print(j)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n,x=map(int, input().split())
a=list(map(int, input().split()))
a.sort()
count=0
i=0
while x>0 and i<n:
    x-=a[i]
    if x>=0:count+=1
    i+=1 
print(count)

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0

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

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

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

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

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

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

        else:
            break
    

print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, x = map(int, input().split())
a = sorted(list(map(int, input().split())))

child = 0
candy = 0

print(a)

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

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

print(child)

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

child = 0
candy = 0

print(a)

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

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

print(int(child))

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

child = 0
candy = 0

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

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

print(int(child))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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))



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


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

res = bisect.bisect_right(S, x) - 1
if res == N and S[-1] != x:
    print(res - 1)
else:
    print(res)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, x = map(int, input().split())
A = sorted(list(map(int, input().split())))

ans = 0
for a in A:
    if x >= a:
        x -= a
        ans += 1

print(ans)

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

ans = 0
for a in A:
    if x >= a:
        x -= a
        ans += 1

if ans == N:
    print(ans - (x != 0))
else:
    print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import math
import heapq
import sys
from collections import Counter




N,x=map(int, input[0].split())  
a=list(map(int,input[1].split()))  

heapq.heapify(a)  

for i in range(N):
    x-=heapq.heappop(a)  
    #print(x,a)
    if x<=0 or i==N-1:
        print(i+1)
        break

import math
import heapq
import sys
from collections import Counter




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

heapq.heapify(a)  

for i in range(N):
    x-=heapq.heappop(a)  
    #print(x,a)
    if x<=0 or i==N-1:
        print(i+1)
        break




import math
import heapq
import sys
from collections import Counter




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

heapq.heapify(a)  

for i in range(N):
    x-=heapq.heappop(a)  
    print(x,a)
    if x<=0 or i==N-1:
        if x==0:
            print(i+1)
        else:
            print(i)
        break
        




import math
import heapq
import sys
from collections import Counter




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

heapq.heapify(a)  

for i in range(N):
    x-=heapq.heappop(a)  
    #print(x,a)
    if x<=0 or i==N-1:
        if x==0:
            print(i+1)
        else:
            print(i)
        break
        




Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# AGC027A - Candy Distribution Again
# greedy algorithm
from itertools import accumulate


def main():
    # maximize the number of proper distribution -> begin with small values
    n, x = tuple(map(int, input().rstrip().split()))
    A = sorted(map(int, input().rstrip().split()))
    ans = sum(i <= x for i in accumulate(A))
    print(ans)


if __name__ == "__main__":
    main()

# AGC027A - Candy Distribution Again
# greedy algorithm
from itertools import accumulate as acc


def main():
    # maximize the number of proper distribution -> begin with small values
    N, X, *A = map(int, open(0).read().split())
    A.sort()
    ac = list(acc(A))
    if ac[-1] < x:  # the last one receives more than expected -> ans - 1
        ans = n - 1
    else:
        ans = sum(i <= x for i in ac)
    print(ans)


if __name__ == "__main__":
    main()

# AGC027A - Candy Distribution Again
# greedy algorithm
from itertools import accumulate as acc


def main():
    # maximize the number of proper distribution -> begin with small values
    N, X, *A = map(int, open(0).read().split())
    A.sort()
    ac = list(acc(A))
    if ac[-1] < X:  # the last one receives more than expected -> ans - 1
        ans = N - 1
    else:
        ans = sum(i <= X for i in ac)
    print(ans)


if __name__ == "__main__":
    main()

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N, X = map(int, input().split())
A = sorted(list(map(int, input().split())))
ans = 0
for i in range(N):
  if X >= A[i]:
    X -= A[i]
    ans += 1
print(ans)

N, X = map(int, input().split())
A = sorted(list(map(int, input().split())))
l = [0]*N
for i in range(N):
  if X >= A[i]:
    if i == N-1:
      l[i] = X
      X -= X
    else:
      l[i] = A[i]
      X -= A[i]
  else:
    l[i] = X
    X -= X
ans = [A[i]-l[i] for i in range(N)].count(0)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys

N, x = sys.stdin.readline().split()
N = int(N)
x = int(x)
al = [int(a) for a in sys.stdin.readline().split()]

al.sort()

used = 0
ans = N
for i, a in enumerate(al):
    if used+a > x:
        ans = i
        break
    used += a

print(ans)
    
        
        


import sys

N, x = sys.stdin.readline().split()
N = int(N)
x = int(x)
al = [int(a) for a in sys.stdin.readline().split()]

al.sort()

used = 0
ans = N
for i, a in enumerate(al):
    if used+a > x:
        ans = i
        break
    elif used+a == x:
        ans = i+1
        break
    used += a

print(ans)
    
        
        


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

al.sort()

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

print(ans)
    
        
        


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

al.sort()

used = 0
ans = N
for i, a in enumerate(al):
    if used+a > x:
        ans = i
        break
    used += a

print(ans)
    
        
        


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

al.sort()

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

print(ans)
    
        
        


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

al.sort()

cum = [sum(al[:i+1])for i in range(len(al))]

ans = N-1
for i in range(len(al)):
    if cum[i] == x:
        ans = i+1
        break
    elif cum[i]>x:
        ans = i
        break
print(ans)
    
        
        


Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n, x = map(int, input().split())
array = list(map(int, input().split()))

count = 0
array = sorted(array, reverse=True)
for i in range(n):
    x = x - array[i]
    if x >= 0:
        count += 1
    else:
        break
print(count)

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

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,x=nii()
a=lnii()
a.sort()

a_sum=0
for i in range(n):
  a_sum+=a[i]
  if a_sum>x:
    print(i)
    exit()

print(n)

from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from bisect import bisect
from itertools import accumulate

n,x=nii()
a=lnii()
a.sort()

b=list(accumulate(a))

if b[-1]<x:
  print(n-1)
else:
  inx=bisect(b,x)
  print(inx)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n,x,*a=map(int,open(0).read().split())
a.sort()
s=0
i=0
while s<x or i<=n:
    i+=1
    s+=a[i]
print(~-i)

n,x,*a=map(int, open(0).read().split())
a.sort()
for i in range(n):
    x-=a[i]
    if x<0:
      print(i)
      exit()
print(n)

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

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):

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)

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)


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)


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:
    x -= ai
    break
if x > 0 and count > 0:
  count -= 1
print(count)


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):

n,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = []
num = a[0]
i = 1

while num <= x:
    num += a[i]
    if x - a[i] > 0:
        x -= a[i]
        b.append(a[i])
        i += 1
    else:
        b.append(max(0,a[i]))
        break

print(a)
print(b)
print(num)

ans = 0
for i in range(min(len(a),len(b))):
    if a[i] == b[i]:
        ans += 1
print(ans)




n,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
b = []
num = a[0]
i = 1

while num <= x:
    num += a[i]
    if x - a[i] > 0:
        x -= a[i]
        b.append(a[i])
        i += 1
    else:
        b.append(max(0,a[i]))
        break
"""
print(a)
print(b)
print(num)
"""
ans = 0
for i in range(min(len(a),len(b))):
    if a[i] == b[i]:
        ans += 1
print(ans)




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

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

if x == a[-1]:
    ans += 1

print(ans)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np
N,x = map(int,input().split())
A = np.array(input().split(), dtype = np.int64)
A.sort()
A = A.cumsum()
answer = (A <= x).sum()
print(answer)

import numpy as np
N,x = map(int,input().split())
A = np.array(input().split(), dtype = np.int64)
A.sort()
np.cumsum(A, out = A)
answer = (A <= x).sum()
print(answer)

import numpy as np
N,x = map(int,input().split())
A = np.array(input().split(), dtype = np.int64)
A.sort()
np.cumsum(A, out = A)
answer = (A <= x).sum()

import numpy as np
N,x = map(int,input().split())
A = np.array(input().split(), dtype = np.int64)
A.sort()
np.cumsum(A, out = A)
answer = (A <= x).sum()
print(answer)


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from bisect import bisect_right
import itertools

N,X,*A = map(int,read().split())

A.sort()
Acum = list(itertools.accumulate(A))

answer = bisect_right(Acum,X)
if answer == N:
    if Acum[-1] < X:
        answer -= 1
print(answer)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):

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)



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

@author: Yuki
"""

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


cnt=0
res=0
for i in range(0,N):
    cnt += A[i]
    if cnt > x:
        res = i
        break
    elif cnt == x:
        res = i+1
        break
    if i == N-1 and cnt < x:
        res = N-1
if A[0] > x:
    res=0
print(res)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)


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


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n,x=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
ans=0
for a in A:
  x-=a
  if x>=0:
    ans+=1
  else:
    print(ans)
    break

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, X = list(map(int, input().split()))
A = list(map(int, input().split()))
ret = 0
for a in A:
    if a <= X:
        ret += 1
        X -= a
print(ret)

N, X = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
last_index = len(A) - 1
ret = 0
for i, a in enumerate(A):
    if a <= X:
        ret += 1
        X -= a
if ret == N and X > 0:
    ret -= 1
print(ret)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
children = list(map(int,input().split())) 
children.sort()
count=0
c = 0
if x < children[0]:
  print(0)
  exit()
for i in range(n):
  count += children[i]
  c += 1
  if count == x:
    print(c)
    exit()
  elif count > x:
    print(c-1)
    exit()

print(n-1)

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

print(n-1)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n,x = map(int,input().split()) 
A= list(map(int,input().split())) 
A.sort()
a_sum=0  
for i in range(n):
    a_sum+= A[i]
    if x<a_sum:
        print(i)
        exit() 

print(n)

n,x = map(int,input().split()) 
A= list(map(int,input().split())) 
A.sort()
a_sum=0  
for i in range(n):
    a_sum+= A[i]
    if x<a_sum:
        print(i)
        exit() 

if a_sum== sum(A):
    print(n)
else:
    print(n-1)

n,x = map(int,input().split()) 
A= list(map(int,input().split())) 
A.sort()
a_sum=0  
for i in range(n):
    a_sum+= A[i]
    if x<a_sum:
        print(i)
        exit() 

if a_sum== x:
    print(n)
else:
    print(n-1)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N,x=map(int,input().split())
a = list(map(int,input().split()))
cnt = 0
a.sort()
for i in a:
    if x >= i:
        x -= i
        cnt +=1
    else:
        print(cnt)
        exit()
print(cnt)

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

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N, x = map(int, input().split())
a = sorted(map(int, input().split()))
cnt = 0
for i in a:
    if x < i:
        break
    cnt += 1
    x -= i
    if x > 0:
        cnt -= 1
print(cnt)

N, x = map(int, input().split())
a = sorted(map(int, input().split()))
cnt = 0
for i in a:
    if x < i:
        break
    cnt += 1
    x -= i
else:
    if x > 0:
        cnt -= 1
print(cnt)

Verdicts: Wrong Answer

Accepted