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):
line = input().split()
x = int(line[1])
ans = 0
 
a = sorted(input().split())
map(int, a)
 
for i in range(len(a)):
  if a[i] > x:
    print(ans)
    break
  else:
    x-=a[i]
    if i!=(len(a)-1):
      ans+=1
    else:
      if x==0:
        ans+=1
      print(ans)

x = input().split()[1]
ans = 0
 
a = input().split()
a.sort()
 
for i in len(a):
  if a[i] > x:
    print(ans)
    break
  else:
    x-=a[i]
    if i!=len(a)-1:
      ans+=1
    else:
      if a[i]==x:
        ans+=1
      print(ans)

line = input().split()
x = line[1]
ans = 0
 
a = input().split().sort()
 
for i in len(a):
  if a[i] > x:
    print ans
    break
  else:
    x-=a[i]
    ans+=1
    continue
print ans

x = input().split()[1]
ans = 0
 
a = input().split()
a.sort()
 
for i in len(a):
  if a[i] > x:
    print ans
    break
  else:
    x-=a[i]
    ans+=1
print ans

line = input().split()
x = line[1]
ans = 0;
 
a = input().split().sort()
 
for i in len(a):
  if a[i] > x:
    print ans
    break
  else:
    x-=a[i]
    ans+=1
    continue
print ans

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)

x = int(input().split()[1])
ans = 0
 
a = input().split()
a.sort()
 
for i in len(a):
  if a[i] > x:
    print(ans)
    break
  else:
    x-=a[i]
    if i!=len(a)-1:
      ans+=1
    else:
      if x==0:
        ans+=1
      print(ans)

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

line = input().split()
x = line[1]
ans = 0;

a = input().split().sort()

for i in len(a):
  if a[i] > x:
    print ans
    break
  else:
    x-=a[i]
    ans++
    continue
print ans

line = input().split()
x = int(line[1])
ans = 0
 
a = sorted(input().split())
map(int, a)
 
for i in len(a):
  if a[i] > x:
    print(ans)
    break
  else:
    x-=a[i]
    if i!=len(a)-1:
      ans+=1
    else:
      if x==0:
        ans+=1
      print(ans)

x = input().split()[1]
ans = 0
 
a = sorted(input().split())
 
for i in len(a):
  if a[i] > x:
    print ans
    break
  else:
    x-=a[i]
    ans+=1
print ans

line = input().split()
x = int(line[1])
ans = 0
 
a = sorted(input().split())
map(int, a)
 
for i in len(a):
  if a[i] > x:
    print(ans)
    break
  else:
    x-=a[i]
    if i!=len(a)-1:
      ans+=1
    else:
      if x==0:
        ans+=1
      print(ans)

x = input().split()[1]
ans = 0
 
a = input().split()
a.sort()
 
for i in len(a):
  if a[i] > x:
    print(ans)
    break
  else:
    x-=a[i]
    if i!=len(a)-1:
      ans+=1
    else:
      if a[i]=x:
        ans+=1
      print(ans)

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

x = input().split()[1]
ans = 0
 
a = input().split()
a.sort()
 
for i in len(a):
  if a[i] > x:
    print(ans)
    break
  else:
    x-=a[i]
    ans+=1
print(ans)

x = int(input().split()[1])
ans = 0
 
a = input().split()
a.sort()
 
for i in len(a):
  if a[i] > x:
    print(ans)
    break
  else:
    x-=a[i]
    if i!=len(a)-1:
      ans+=1
    else:
      if a[i]==x:
        ans+=1
      print(ans)

line = input().split()
x = int(line[1])
ans = 0
 
a = sorted(input().split())
 
for i in len(a):
  if a[i] > x:
    print(ans)
    break
  else:
    x-=a[i]
    if i!=len(a)-1:
      ans+=1
    else:
      if x==0:
        ans+=1
      print(ans)

line = input().split()
x = int(line[1])
ans = 0
 
a = sorted(input().split())
 
for i in len(a):
  map(int, a[i])
  if a[i] > x:
    print(ans)
    break
  else:
    x-=a[i]
    if i!=len(a)-1:
      ans+=1
    else:
      if x==0:
        ans+=1
      print(ans)

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)

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)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Accepted