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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,X = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
B = 0
result = A[0]
while result <= X:
  result += A[B]
  B += 1
print(B)

Submission status: Runtime Error

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

if x == sum(a):
    print(n)
elif x > sum(a):
    print(n-1)
else:
    for i in a:
        sum += i
        people += 1
        if sum > x:
            print(people-1)
            break

Submission status: Runtime Error

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
sum = 0
count = 0
while True:
  sum += a[0]
  if sum > x or len(a) == 0:
    break
  count += 1
  del a[0]
print(count)

Submission status: Runtime Error

Solution code:
# 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()

Submission status: Runtime Error

Solution code:
N, x = map(int, input().split())
an = list(map(int, input().split()))
an.sort()
flag = [0]*N
count = 0
i = 0
xs = x
while(1):
  if x >= an[i]:
    x -= an[i]
    if flag[i] == 0:
      flag[i] += 1
      count += 1
    elif flag[i] == 1:
      flag[i] += 1
      count -= 1
      i = 0
    else:
      i = 0
  if x == 0:
    break
  i += 1
  if i >= N:
    i = 0
    if xs == x:
      break
print(count)v

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

a.sort()
temp_x = x
for i in range(n):
  if temp_x > 0:
    temp_x += -a[i]
  else:
    ans = i
    break
print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
n, x = [ int(v) for v in input().split() ]
candy_list = sorted([ int(v) for v in input().split() ])
candy_list_2 = cumsum(candy_list)

if sum(candy_list) <= x:
    print(n)
else:
    for i in range(n):
        if candy_list_2[i] > x:
            print(i)
            break

Submission status: Runtime Error

Solution code:
 _, X = map(int, input().split())
A = sorted(list(map(int, input().split())))

count = 0
for a in A:
    if X - a >= 0:
        X -= a
        count += 1
else:
    if count > 1 and X > 0:
        count -= 1

print(count)

Submission status: Runtime Error

Solution code:
 _, X = map(int, input().split())
A = sorted(list(map(int, input().split())))

count = 0
for a in A:
    if a > X:
        break
    X -= a
    count += 1

if X > 0:
    count -= 1

print(count)

Submission status: Runtime Error

Solution code:

import bisect


n, x = map(int, input().split())
a = list(sorted(map(int, input().split())))
if x == sum(x):
    print(n)
else:
    acc = [0 for i in range(n)]
    acc[0] = a[0]
    for i in range(1, n):
        acc[i] += a[i - 1] + a[i]
    index = bisect.bisect_right(acc, x)
    if index == n:
        print(index - 1)

Submission status: Runtime Error

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
if sum(a) == x:
  print(N)
else:
  while sum(a) > x:
    a.remove(max(a))
  print(len(l))

Submission status: Runtime Error

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
if sum(a) == x:
  print(N)
else:
  sort(a)
  while sum(a) > x:
    a.remove(max(a))
  print(len(l))

Submission status: Runtime Error

Solution code:
[n,x] = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
accsum = [0]
for i in range(n):
    if accsum[i] >= x:
        break
    accsum.append(accsum[i] + a[i])

#print(i)
#print(accsum)
if accsum[i+1] == x:
    print(i+1)
else:
    print(i)

Submission status: Runtime Error

Solution code:
n,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
s=a[0]
i=0
while s<=x and i<n:
  i+=1
  s+=a[i]
print(i)

Submission status: Runtime Error

Solution code:
n,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
s=a[0]
i=0
while s<=x:
  i+=1
  s+=a[i]
print(i)

Submission status: Runtime Error

Solution code:
n,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
s=a[0]
i=0
while s<x:
  i+=1
  s+=a[i]
print(i)

Submission status: Runtime Error

Solution code:
n,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
s=0
i=0
while s<x:
  s+=a[i]
  i+=1
print(i+1)

Submission status: Runtime Error

Solution code:
n, x = map(int, input().split())
a = map(int, input().split())
num = len(a)
a.sort(reverse=True)
for i in range(num):
    x -= a.pop()
    if x < 0:
        print(i)
        exit()
    if x == 0:
        print(i + 1)
        exit()
print(num - 1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from bisect import bisect_right

n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
SUM = [a[0]]

for i in range(1, n):
    SUM.append(SUM[-1]+a[i])

if SUM[-1] < x:
    print(n-1)
else:
    print(bisect_right(x, SUM))

Submission status: Runtime Error

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

i = 0

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

print(i)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
N, x = map(int, input().split())
a = input().split()
for i in range(len(a)):
    a[i] = int(a[i])

for i in range(N):
    idx = np.argmin(a[i:]) + i
    temp = a[i]
    a[i] = a[idx]
    a[idx] = temp

sum = 0
for i in range(N):
    sum += a[i]

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

Submission status: Runtime Error

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

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

a.sort()
i=0
ans=0

while x>0:
    if x-a[i]>=0:
        x-=a[i]
        ans+=1
    else:
        x=0
    i+=1

print(ans)

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
s = list(input())
out = [set() for _ in range(n)]
count = [[0, 0] for _ in range(n)]
def f(c):
    if c == 'A': return 0
    else: return 1
for _ in range(m):
    a, b = map(int, input().split())
    if a == b:
        count[a-1][f(s[a-1])] += 1
    elif b-1 not in out[a-1]:
        count[a-1][f(s[b-1])] += 1
        count[b-1][f(s[a-1])] += 1
    out[a-1].add(b-1)
    out[b-1].add(a-1)
elim = set()
def eliminate(x):
    elim.add(x)
    c = f(s[x])
    for node in out[x]:
        if node not in elim:
            count[node][c] -= 1
            if count[node][0] * count[node][1] == 0:
                eliminate(node)
for i in range(n):
    if i not in elim and count[i][0] * count[i][1] == 0:
        eliminate(i)
if len(elim) < n: print('Yes')
else: print('No')

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

import sys, re
from collections import deque, defaultdict, Counter
from math import gcd, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, initial=1)
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, X = MAP()
aN = LIST()

aN.sort()
sm = sum(aN)
if sm < X:
    print(N-1)
elif sm == X:
    print(N)
else:
    x = X
    for i in range(N):
        x -= aN[i]
        if x < 0:
            print(i)
            exit()

Submission status: Runtime Error

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

Submission status: Runtime Error

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:]))
t

Submission status: Runtime Error

Solution code:
N,x = map(int,input().split())
a = list(map(int,input().split()))
if min(a) > x:
  print("0")
else:
  b = sorted(a)
  i = 0
  while x > b[i]:
    x = x - b[i]
    i = i+1
print(i)

Submission status: Runtime Error

Solution code:
N,x = map(int,input().split())
a = list(map(int,input().split()))
if min(a) > x:
  print("0")
else:
  b = sorted(a)
  i == 0
  while x < b[i]:
    x = x - b[i]
    i = i+1
print(i)

Submission status: Runtime Error

Solution code:
n=int(input())
if n == 1:
	print('Hello World')
if n == 2:
	a=int(input())
	b=int(input())
	print(a+b)

Submission status: Runtime Error

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:
            if x > list[i]:
                a = n-1
            else:
                a = n
            break
        i += 1

    print(a)

Submission status: Runtime Error

Solution code:
# AtCorder-Candy Distribution Again

n,x = map(int, input().split())
list[n] = 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:
            if x > list[i]:
                a = n-1
            else:
                a = n
            break
        i += 1

    print(a)

Submission status: Runtime Error

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 x < list[i+1]:
            break
        i += 1

    print(a)

Submission status: Runtime Error

Solution code:

#入力した型を数値に変換し、1行のデータを分割
#map()関数
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)

Submission status: Runtime Error

Solution code:
# 27
n,x = list(map(int, input().split()))
aa = list(map(int, input().split()))
aa.sort()
ans = 0
for a in aa:
    if x<a:
        break
    ans+=1
    x-=ai
else:    #for else文 - breakすると入らないことを利用=ループ完遂した場合の終端処理
    if x>0:
        ans-=1
print(ans)

Submission status: Runtime Error

Solution code:
# 27
n,x = list(map(int, input().split()))
aa = list(map(int, input().split()))
aa.sort()
ans = 0
for a in aa:
    if x<a:
        break
    ans+=1
    x-=ai
else:    #for else文 - breakすると入らないことを利用=ループ完遂した場合の終端処理
    if x>0:
        ans-=1
print(num)

Submission status: Runtime Error

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

Submission status: Runtime Error

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 calc_energy(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: Runtime Error

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

A.sort()

ans = 0

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
if __name__ == "__main__":
    N,x = list(map(int, input().split()))
    a = list(map(int, input().split()))
    A = 0

    a.sort()
    print(a)
    while x >= 0:
        if a[-1] < x:
            x -= a.pop(-1)
            A += 1
        else:
            break

    if x != 0:
        A -= 1
    print(A)

Submission status: Runtime Error

Solution code:
N, x = map(int, input().split())
a = map(int, input().split())
arr = sorted(a)
ptr = 0
cnt = 0
if a.sum() == 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: Runtime Error

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: Runtime Error

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


print(ans)

Submission status: Runtime Error

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 = 0
for i in range(N):
  sum_candy += a[i]
  if sum_candy > x:
    break
print(i)

Submission status: Runtime Error

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]
  else:
    count += 1
print(count)

Submission status: Runtime Error

Solution code:
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: Runtime Error

Solution code:
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "stack"

#define lp(n) for (int i = 0; i < n; ++i)
#define LP(n,i) for (int i = 0; i < n; ++i)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define P pair<ll,ll>
typedef long long ll;
using namespace std;

ll n,m,t,A[100000],a,b,c,g1[100000],g2[100000],ans;
vector<P>v1[100000],v2[100000];
priority_queue<P,vector<P>,greater<P>>q;

int main(){
    cin>>n>>m>>t;
    lp(n){
        cin>>A[i];
        g1[i]=g2[i]=llmax;
    }
    lp(m){
        cin>>a>>b>>c;
        v1[a-1].push_back(mkp(b-1,c));
        v2[b-1].push_back(mkp(a-1,c));
    }
    g1[0]=0;
    g2[0]=0;
    lp(v1[0].size())
        q.push(mkp(v1[0][i].second,v1[0][i].first));
    while(!q.empty()){
        if(g1[q.top().second]==llmax){
            g1[q.top().second]=q.top().first;
            lp((int)v1[q.top().second].size()){
                if(g1[v1[q.top().second][i].second]==llmax)
                    q.push(mkp(v1[q.top().second][i].second+g1[q.top().second],v1[q.top().second][i].first));
            }
        }
        q.pop();
    }
    lp(v2[0].size())
		q.push(mkp(v2[0][i].second,v2[0][i].first));
    while(!q.empty()){
        if(g2[q.top().second]==llmax){
            g2[q.top().second]=q.top().first;
            lp((int)v2[q.top().second].size()){
                if(g2[v2[q.top().second][i].second]==llmax)
                    q.push(mkp(v2[q.top().second][i].second+g2[q.top().second],v2[q.top().second][i].first));
            }
        }
        q.pop();
    }
    ans=0;
    lp(n){
		cout<<i<<sp<<g1[i]<<sp<<g2[i]<<endl;
		if(g1[i]!=llmax&&g2[i]!=llmax)
			ans=max(ans,(t-g1[i]-g2[i])*A[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Submission status: Runtime Error

Solution code:


n,m = map(int,input().split())
s = list(input())
edges = [tuple(map(int,input().split())) for i in range(m)]


def addEdge(graph,u,v):
    graph[u].add(v)


def deleteNode(graph,node):
    graph.pop(node,None)

from collections import defaultdict
graphAB = defaultdict(set)
graphABopp = defaultdict(set)

connodes = set()
for i,j in edges:
    ii = min(i,j)
    jj = max(i,j)
    addEdge(graphAB,ii,jj)
    addEdge(graphABopp,jj,ii)
    if i != j:
        connodes.add(i)
        connodes.add(j)



def adjAB(node):
    Aflag = 'A' in map(lambda x:s[x-1],graphAB[node])
    Aflag = Aflag or 'A' in map(lambda x:s[x-1],graphABopp[node])
    Bflag = 'B' in map(lambda x:s[x-1],graphAB[node])
    Bflag = Bflag or 'B' in map(lambda x:s[x-1],graphABopp[node])
    if Aflag and Bflag:
        return(True)
    else:
        return(False)



visitlist = [i for i in connodes if not adjAB(i)]
#print(visitset)

while bool(visitlist):
    i = visitlist.pop()
    for j in graphAB[i]:
        graphABopp[j].remove(i)
        if not adjAB(j):
            visitlist.append(j)
            #print(visitset,'add')
    for j in graphABopp[i]:
        graphAB[j].remove(i)
        if not adjAB(j):
            visitlist.append(j)
            #print(visitset,'add')
    graphAB.pop(i,None)
    graphABopp.pop(i,None)

#print(graphAB)
#print(graphABopp)


if graphAB == {} and graphABopp == {}:
    print('No')
else:
    print('Yes')

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
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

Submission status: Runtime Error

Solution code:
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

Submission status: Runtime Error

Solution code:
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

Submission status: Runtime Error

Solution code:
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

Submission status: Runtime Error

Solution code:
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

Submission status: Runtime Error

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_ary = [int(a) for a in input().split()]
    print(solve(N, x, a_list))

Submission status: Runtime Error

Solution code:
N = int(input())
x = int(input())
cage = []
for i in range(N):
    nu = int(input())
    cage.append(nu)
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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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: Runtime Error

Solution code:
N = int(input())
x = int(input())
y=x
cage = list(map(int,input().split()))
ans=0
for i in range(N):
    ind = cage.index(min(cage))
    if(min(cage) > x):
        break
    x = x - min(cage)
    cage[ind] = y
    ans += 1
if x>0:
    ans = ans - 1
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
x = int(input())
y=x
cage = []
for i in range(N):
    nu = int(input())
    cage.append(nu)
ans=0
for i in range(N):
    ind = cage.index(min(cage))
    if(min(cage) > x):
        break
    x = x - min(cage)
    cage[ind] = y
    ans += 1
if x>0:
    ans = ans - 1
print(ans)

Submission status: Runtime Error

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

tab = [[None] * (x + 1) for i in range(N)]

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

print(max(0, recsearch(0, x)))

Submission status: Runtime Error

Solution code:
N = int(input())
x = int(input())
cage = []
for i in range(N):
    nu = int(input())
    cage.append(nu)
ans=0
for i in range(N):
    ind = cage.index(min(cage))
    if(min(cage) > x):
        break
    x = x - min(cage)
    cage[ind] = "no"
    ans += 1
if x>0:
    ans = ans - 1
print(ans)