Problem:


Score : 400 points

Problem Statement

Snuke found N strange creatures.
Each creature has a fixed color and size. The color and size of the i-th creature are represented by i and A_i, respectively.

Every creature can absorb another creature whose size is at most twice the size of itself.
When a creature of size A and color B absorbs another creature of size C and color D (C \leq 2 \times A), they will merge into one creature of size A+C and color B.
Here, depending on the sizes of two creatures, it is possible that both of them can absorb the other.

Snuke has been watching these creatures merge over and over and ultimately become one creature.
Find the number of the possible colors of this creature.

Constraints

2 \leq N \leq 100000

1 \leq A_i \leq 10^9

A_i is an integer.

Input

The input is given from Standard Input in the following format:

N
A_1 A_2 … A_N

Output

Print the number of the possible colors of the last remaining creature after the N creatures repeatedly merge and ultimately become one creature.

Sample Input 1

3
3 1 4

Sample Output 1

2

The possible colors of the last remaining creature are colors 1 and 3.
For example, when the creature of color 3 absorbs the creature of color 2, then the creature of color 1 absorbs the creature of color 3, the color of the last remaining creature will be color 1.

Sample Input 2

5
1 1 1 1 1

Sample Output 2

5

There may be multiple creatures of the same size.

Sample Input 3

6
40 1 30 2 7 20

Sample Output 3

4



Sample input:
3
3 1 4


Sample output:
2

Submission status: Accepted

Solution code:
input()
A = list(map(int, input().split())); A.sort()

s = 0
l = 0
for i in range(len(A)):
    if s * 2 < A[i]:
        l = i
    s += A[i]
print(len(A) - l)

Submission status: Accepted

Solution code:
import numpy as np

N = int(raw_input())
A = map(lambda x:int(x), raw_input().split())

A.sort()

A = np.asarray(A)
S = np.zeros_like(A)
s=0
for i in range(N):
    s += A[i]
    S[i] = s

#print A
#print S
index = np.where(A[1:] - S[:-1]*2 > 0)[0]
if index.shape[0]:
    print N - index[-1]-1
else:
    print N

Submission status: Accepted

Solution code:
n = input()
A = map(int, raw_input().split())
A.sort()
s = 0
ans = 1
for a in A:
    if a <= 2*s:
        ans += 1
    else:
        ans = 1
    s += a
print ans

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    n = II()
    a = LI()
    a.sort()
    r = 1
    t = a[0]
    for ai in a[1:]:
        if t*2 < ai:
            r = 1
        else:
            r += 1
        t += ai

    return r

print(main())

Submission status: Accepted

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

def identity(x):
    return x

def mapv(f,s):
    return list(map(f,s))

def readln():
    _res = mapv(int,str(input()).split(' '))
    return _res

def seq(n,f=(lambda x: 0)):
    return [f(i) for i in range(0,n)]

n = int(input())
a = sorted(readln())
s = seq(n)
v = 0
s[0] = a[0]
for i in range(1,n):
    s[i] = s[i-1] + a[i]
for i in range(1,n):
    index = n - 1 - i
    if s[index] << 1 >= a[index + 1]:
        v = i + 1
    else: break
print(v)

Submission status: Accepted

Solution code:
n = input()
a = map(int,raw_input().split(' '))
a.sort(reverse=True)
s = 0
t = n
for i in xrange(len(a)-1,1,-1) :
    s += a[i]
    if s * 2 < a[i-1] : t = i
print t

Submission status: Accepted

Solution code:

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

l = 0
size = 0

for i in range(N - 1):
    size += A[i]

    if A[i + 1] > 2 * size:
        l = i + 1

ans = N - l

print(ans)

Submission status: Accepted

Solution code:

def paku(N, A, mid):
    if mid == 0:
        return False

    size = sum(A[:mid])

    for i in range(mid, N):
        if A[i] <= 2*size:
            size += A[i]
        else:
            return False

    return True


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

top = N
btm = 0

while top - btm > 1:
    mid = (top + btm) // 2

    if paku(N, A, mid):
        top = mid
    else:
        btm = mid

ans = N - top + 1

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

num = int(input())
l_cre = list(map(int, input().split()))
l_cre.sort()

counter = 0
now_size = 0

for i in range(len(l_cre) - 1):
    now_size += l_cre[i]
    if now_size * 2 >= l_cre[i + 1]:
        counter += 1
    else:
        counter = 0

counter += 1

print(counter)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))

    A.sort()
    i = 1
    j = N - 1
    x = sum(A)
    while j > 0:
        if (x - A[j]) * 2 >= A[j]:
            i += 1
        else:
            break
        x -= A[j]
        j -= 1
    print(str(i))

main()

Submission status: Accepted

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

n.sort()
SUM = 0
count = 0
for i in range(len(n)-1):
    SUM += n[i]
    if n[i+1] > SUM*2:
        count = i+1
print(len(n)-count)

Submission status: Accepted

Solution code:

N=input()
A=map(int, raw_input().split())
A.sort()


cur = 0
brk=0
for i in xrange(len(A)):
    v=A[i]
    if i !=0 and v > cur*2:
#        print "brk",i
        brk=i
    cur+=v

print len(A) - brk

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from itertools import accumulate


def main():
    # 入力処理
    N = int(input())
    As = sorted([int(x) for x in input().split()])
    print(As, file=sys.stderr)

    # アルゴリズム本体
    Bs = list(accumulate(As))
    print(Bs, file=sys.stderr)

    M = 0
    Rs = [A / B for A, B in zip(As[1:N], Bs[0:N-1])]
    for i, R in enumerate(Rs):
        if R > 2:
            M = i + 1

    # 出力
    print(N - M, file=sys.stderr)
    print(N - M)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(raw_input())
A = map(int, raw_input().split())
A.sort()

sum = A[0]
ans = 1
for a in A[1:]:
	if sum*2 < a:
		ans = 1
	else:
		ans += 1
	sum += a
print ans

Submission status: Accepted

Solution code:
def gattai(ar,i):
    sm = sum(ar[:i+1])
    idx = i
    while True:
        if idx == len(ar)-1:
            return len(ar)
        elif ar[idx+1] <= sm*2:
            sm += ar[idx+1]
            idx += 1
            continue
        else: return i-idx-1

n = int(input())
ar = list(map(int, input().split()))
ar.sort()

ans = 0
idx = 0
while ans <= 0:
    hoge = gattai(ar, idx)
    ans += hoge
    idx = abs(ans)

print(ans)

Submission status: Accepted

Solution code:
def search_sorted(x, xs):
    '''
    >>> search_sorted(3, range(10))
    3
    >>> search_sorted(3, [0, 1, 3, 3, 3, 5])
    4
    >>> search_sorted(3, [0, 1, 3, 3])
    3
    >>> search_sorted(1, [1, 1])
    1
    '''
    i = 0
    j = len(xs)
    while j - i > 1:
        m = (i + j) // 2
        if xs[m] <= x:
            i = m
        elif x < xs[m]:
            j = m
    return i

class FenwickTree:
    '''
    >>> tree = FenwickTree(5)
    >>> tree.add(0, 3)
    >>> tree.add(4, 2)
    >>> tree.add(2, 7)
    >>> tree.sum(5)
    12
    >>> tree.sum(3)
    10
    >>> tree.sum(2)
    3
    >>> tree.sum(1)
    3
    >>> tree.sum(0)
    0

    '''
    def __init__(self, n):
        self.array = [0] * n

    def add(self, i, x):
        while i < len(self.array):
            self.array[i] += x
            w = (i + 1) & -(i + 1)
            i += w

    def sum(self, i):
        i -= 1
        s = 0
        while i >= 0:
            s += self.array[i]
            w = (i + 1) & -(i + 1)
            i -= w
        return s


def solve():
    input()
    A = list(map(int, input().split())); A.sort()
    tree = FenwickTree(len(A))
    for i, a in enumerate(A):
        tree.add(i, a)

    answer = 0
    for i in range(len(A)):
        a = A[i]
        j = i
        while True:
            j = search_sorted(a * 2, A)
            a_ = tree.sum(j + 1)
            if a == a_:
                break
            else:
                a = a_
        if j + 1 == len(A):
            answer += 1
    print(answer)

solve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())

C = list(map(int, input().split()))

C.sort(reverse=True)

color = 0
size  = -1
comp  = 0
c_color = 0
c_update = True
for i in range(0, N):
    # C[i] can eat the bigger one
    if C[i] >= size / 2:
        color += 1
        size = C[i]
        continue
    # need to eat some
    else:
        comp += C[i]
        if c_color == 0 or (c_update and C[i -1] <= C[i] * 2):
            c_color += 1
        else:
            c_update = False
    # some composite creature can eat it
    if comp >= size/2:
        color += c_color
        size = comp
        comp = 0
        c_color = 0
        c_update = True
print(color)

Submission status: Accepted

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

a.sort()

left = 0
right = N

center = (left+right)//2

def check(i):
	s = sum(a[:i+1])
	now = s
	# print("now",a[:i+1])
	for j in range(i, N-1):
		# print("vs",now,a[j+1])
		if now*2 < a[j+1]:
			return(False)
		now += a[j+1]
	# print("now",s)
	return(True)

while right - left > 1:
	center = (left+right)//2
	# print("check",a[center],center)
	if check(center):
		right = center
		# print("able")
	else:
		left = center
		# print("not")

if check(left):
	print(N-left)
else:
	print(N-right)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

input()
A = list(reversed(sorted([int(x) for x in input().split()])))
total = sum(A)
for i, a in enumerate(A):
    total -= a
    if total * 2 < a:
        break
print(i + 1)

Submission status: Accepted

Solution code:
import math
def main():
    global N, A
    N = int(input())
    sizes = list(map(int, input().split()))
    A = list(zip(list(range(1, N+1)), sizes))  # color, size
    A.sort(key=lambda x:x[1])
    print(N - binary_search_for_integer(N-1, -1))

def binary_search_for_integer(ok, ng):
    while math.fabs(ok-ng) > 1:
        mid = (ok+ng)//2
        if solve(mid):
            ok = mid
        else:
            ng = mid
    return ok

def solve(x):  # x=index
    if x != 0:
        size = sum([a[1] for a in A[:x]]) + A[x][1]
    else:
        size = A[x][1]

    for i in range(1, N-x):
        if A[x+i][1] <= 2*size:
            size += A[x+i][1] 
        else:
            return False

    return True


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from bisect import bisect_left

n=int(raw_input())
a=map(int,raw_input().split())
sa=sorted(a)
s=[0]*n
s[0]=sa[0]
for i in xrange(n-1):
    s[i+1]+=s[i]+sa[i+1]
idx=bisect_left(sa,(sa[n-1]+1)/2)
ans=n-idx
f=0
for i in xrange(idx-1,-1,-1):
    if f==0 and s[i]*2>=sa[i+1]:
        f=1
        ans+=1
    else:
        if f==1 and s[i]*2>=sa[i+1]:
            ans+=1
        else:
            break
print ans

Submission status: Accepted

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

a = A[0]
n = 0
for i in xrange(1, N):
    if 2*a < A[i]:
        n = i
    a += A[i]
print N - n

Submission status: Accepted

Solution code:
n = input()
a = map(int, raw_input().split())
a = sorted(a)

cumsums = []
cum = 0
for i in xrange(n):
    cum += a[i]
    cumsums.append(cum)
i = n - 1
survivors = 1
while i > 0:
    if a[i] <= cumsums[i-1] * 2:
        survivors += 1
        i -= 1
        continue
    break
print survivors

Submission status: Accepted

Solution code:
import sys

INF = 10**9+7

stdin = sys.stdin
def na(): return map(int, stdin.readline().split())
def nal(): return list(map(int, stdin.readline().split()))
def ns(): return stdin.readline().strip()
def nsl(): return list(stdin.readline().strip())
def ni(): return int(stdin.readline())


n = ni()
a = nal()

m = max(a)
a.sort()

c = 0
tmp = 0
for i in range(n-1):
    tmp = a[i] + tmp
    if(tmp*2 < a[i+1]):
        c = i+1


print(n - c)

Submission status: Accepted

Solution code:
# coding: utf-8
def getLnInputs():
    return input().split()


def getLnIntInputs():
    return list(map(int, getLnInputs()))


def main():
    N = getLnIntInputs()[0]
    A = sorted(getLnIntInputs())

    eatables = []
    eatables_sum = 0

    for c in range(N):
        if len(eatables) <= c:
            eatables.append(A[c])
            eatables_sum += A[c]

        for idx in range(len(eatables), N):
            s = A[idx]
            if s > 2 * eatables_sum:
                break
            eatables.append(s)
            eatables_sum += s

        if len(eatables) == N:
            print(N - c)
            break

    return


main()

Submission status: Accepted

Solution code:
N = int(raw_input())
A = sorted(map(int, raw_input().split()))

def check(i):
    x = A[i]
    for j, a in enumerate(A):
        if j == i:
            continue
        if a > x * 2:
            return False
        else:
            x += a
    return True

if check(0) == True:
    print N
    exit()
if check(N-1) == False:
    print 0
    exit()

low = 0
high = N - 1
t = (low + high) / 2
while high - low > 1:
    v = check(t)
    if v:
        high = t
    else:
        low = t
    t = (low + high) / 2
print N - t - 1

Submission status: Accepted

Solution code:
N = int(input())
AA = sorted(map(int, input().rstrip().split()))
cur_size = AA[0]
colorSum = 1
for A in AA[1:]:
    if cur_size * 2 >= A:
        colorSum += 1
    else:
        colorSum = 1
    cur_size += A
print(colorSum)

Submission status: Accepted

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

a_sum = [0 for i in range(n)]
a_sum[0] = a[0]
for i in range(1, n):
    a_sum[i] = a_sum[i - 1] + a[i]

cnt = 1
for i in range((n - 1) - 1, -1, -1):
    if a[i + 1] <= a_sum[i] * 2:
        cnt += 1
    else:
        break

print(cnt)

Submission status: Accepted

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

a.sort()
a.reverse()
s = sum(a)

i = 1
for x in a:
  if x > (s - x)*2:
    break
  else:
    s -= x
    i += 1

print(i)

Submission status: Accepted

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

As = sorted(As,reverse=True)

def d(*arg):
    # print(' '.join(map(str,arg)))
    pass

last = 0
ret = 0
leng = len(As)
for idx,a in enumerate(As):
    if 2*a < last:
        if 2*sum(As[idx:])>=last:
            ret += 1
            d('\t',last,ret,leng,idx,a)
        else:
            d('\t',last,ret,leng,idx,a)
            break
            # pass
    else:
        d('\t',last,ret,leng,idx,a)
        ret += 1
    d('\t\t',last,ret,leng,idx,a)
    last = a
print(ret)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

EPS = 1e-9

#http://www.deqnotes.net/acmicpc/2d_geometry/lines
def dot(a, b):
    return a.real * b.real + a.imag * b.imag

def cross(a, b):
    return a.real * b.imag - a.imag * b.real

def distance(a, b, c):
    if dot(b-a, c-a) <= EPS:
        return abs(c-a)
    if dot(a-b, c-b) <= EPS:
        return abs(c-b)
    return abs(cross(b-a, c-a)/(b-a))

N = n()
A = ln()

A.sort()

cum = [A[0]]
for a in A[1:]:
    cum.append(cum[-1] + a)

#print cum

#for i, a in enumerate(A):
#    print i, a

x2 = len(A) - 1
result = 1
for i in xrange(len(A) - 2, -1, -1):
    #while A[x2] > 2 * A[i] and x2 > 0:
    #    x2 -= 1
    #cum[x2] - A[i]
    if cum[i] * 2 < A[i + 1]:
       break
    
    result += 1

print result

Submission status: Accepted

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

A.sort()

answer = 0
size_sum = 0

for i in range(N):
    if size_sum * 2 < A[i]:
        answer = 0
    
    size_sum += A[i]
    answer += 1

print(answer)

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate

def solve():
    N = int(input())
    A = [int(i) for i in input().split()]
    A.sort()
    Ac = list(accumulate(A))

    ans = 1
    # print(Ac)

    for i in range(N - 2, -1, -1):
        if Ac[i] * 2 >= A[i + 1]:
            ans += 1
        else:
            print(ans)
            return

    print(ans)


def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(map(int, input().split()))
s = 0
cur = 0
for i, v in enumerate(a):
  if v > 2*s: cur = i
  s += v
print(n-cur)

Submission status: Accepted

Solution code:
length = int(input())
target = []
target = [int(n) for n in input().split(" ")]
target.sort()
answer = length
temp_len = 0
for i,t in enumerate(target):
    if i == 0:
        before = t
    elif before * 2 < t:
        before += t
        answer -= temp_len
        temp_len = 0
    else:
        before += t
    temp_len += 1
print(answer)

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    n = int(stdin.readline())
    a = map(int, stdin.readline().split())
    a.sort()
    s = a[0]
    u = 0
    for i, x in enumerate(a[1:], 1):
        if x > s * 2:
            u = i
        s += x
    print n - u
main()

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
accumuration = [A[0]]
for i in range(1,N):
	accumuration.append(accumuration[i-1]+A[i])
for i in range(N):
	if accumuration[N-i-2]*2 < A[N-1-i]:
		print(i+1)
		exit()
print(N)

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int, input().split()))
As.sort()

s = 0
ans = 0
for i in range(len(As)-1):
	s += As[i]
	if s * 2 >= As[i+1]:
		ans += 1
	else:
		ans = 0
ans += 1
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
ans=0
sum=0
A.sort()
for i in range(N-1):
	sum+=A[i]
	if A[i+1]>2*sum:
		ans=i+1
print(N-ans)

Submission status: Accepted

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

A = [(a, 1) for a in A]
for i in range(N - 1):
    if A[i][0] * 2 >= A[i + 1][0]:
        A[i + 1] = (A[i][0] + A[i+1][0], A[i][1] + 1)
    else:
        A[i + 1] = (A[i][0] + A[i+1][0], 1)
print(A[N - 1][1])

Submission status: Accepted

Solution code:
n = int(raw_input())
a = [int(x) for x in raw_input().split()]

a.sort()

s = a[0]
m = 0
for i in xrange(1, n):
	if s * 2 < a[i]:
		m = i
	s += a[i]

print(n - m)

Submission status: Runtime Error

Solution code:
from fractions import gcd
from functools import reduce


N, K = map(int, input().split())
A = list(map(int, input().split()))
g = reduce(gcd, A)
if K <= max(A) and K % g == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Submission status: Runtime Error

Solution code:
N=int(input())
A=sorted(list(map(int,input().split(' '))))
acc=[A[0]]
for i in A[1:]:
    acc.append(A[-1]+i)
for i in range(N):
    if acc[i]*2<acc[i+1]:
        print(N-i-1)
        break
    elif i==N-1:
        print(1)
        break

Submission status: Runtime Error

Solution code:
import heapq
n = int(input())
A = list(map(int, input().split()))
heapq.heapify(A)

cnt = 1
prev = heapq.heappop(A)
while A:
    x = heapq.heappop(A)
    if prev > x:
        heapq.heappush(A, prev)
        prev = x
        continue
    print(prev, x, A, cnt)
    if 2*prev < x:
        cnt = 1
    else:
        cnt += 1
    prev += x

print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int,input().split()))
m = max(A)
B = [0] * (m+1)
for i in range(n):
    B[A[i]] += 1
for i in range(1, m+1):
    B[i] = B[i-1] + B[i] * i

# print(B)

ans = 0
for i in range(n):
    ma = -1
    mm = A[i]
    while mm <= m and ma != mm:
        ma = mm
        mm = B[mm]
    if mm > m:
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
flag=0
ans=1
a_cumulative=[0]
for i in range(n):
  flag+=a[i]
  a_cumulative.append(flag)
a.reverse()
a_cumulative.reverse()
for j in range(n-1):
  if a[j]＜= a_cumulative[j+1]*2:
    ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))
# import sys
# input = sys.stdin.readline

N=one_int()

A=many_int()

A=sorted(A)
sums_A=list(it.accumulate(A))

for i in range(N-1):
    if 2*sums_A[i] < A[i+1]: 
        break

if len(set(A))==1:
    print(N)
else:
    print(N-i-1)

Submission status: Runtime Error

Solution code:
5
1 1 1 1 1

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
def main():
	N = int(input())
	a = list(map(int,input().split()))
	a.sort(reverse=True)
	sum_list = [a[0]]
	for i in range(N-1):
		sum_list.append(sum_list[i]+a[i+1])
	count = 1
	sum(a) = A
	for i in range(N):
		if (A-sum_list[i])*2 >= a[i]:
			count += 1
		else:
			break

	print(count)

if __name__ == "__main__":
	main()

Submission status: Runtime Error

Solution code:
import numpy as np

n=int(input())
a=[]

for _ in range(n):
    x=int(input())
    a.append(x)
a = np.sort(a)
a = a[::-1]
count = 1

for i in range(1,len(a)):
    if (a[i]*2 >= a[i-1]):
        count = count+1
    else:
        sub = np.sum(a[i:])
        if (sub*2 >= a[i-1]):
            count = count+1
        else:
            break

print(count)

Submission status: Runtime Error

Solution code:

x= int(input())
y= input().split()
z= list()
for i in y:
    z.append(int(i))
y = z

def funct(mons, curr, possible):
    if not possible:
        return False
    if len(mons) == 0:
        return True
    if 2*curr >= max(mons):
        return True
    smallestMons = min(mons)
    if 2*curr >= smallestMons:
        curr = curr + smallestMons
        mons.remove(smallestMons)
        if funct(mons, curr, True):
            return True
        else:
            return False
    else:
        return False

count = 0
for i in range(0, len(y)):
    tempY = list(y)
    tempY.remove(y[i])
    if funct(tempY, y[i], True):
        count += 1
print(count)

Submission status: Runtime Error

Solution code:

x= int(input())
x = input()
z= list()
for i in y:
    z.append(int(i))
y = z

def funct(mons, curr, possible):
    if not possible:
        return False
    if len(mons) == 0:
        return True
    if 2*curr >= max(mons):
        return True
    smallestMons = min(mons)
    if 2*curr >= smallestMons:
        curr = curr + smallestMons
        mons.remove(smallestMons)
        if funct(mons, curr, True):
            return True
        else:
            return False
    else:
        return False

count = 0
for i in range(0, len(y)):
    tempY = list(y)
    tempY.remove(y[i])
    if funct(tempY, y[i], True):
        count += 1
print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())),reverse=True)
mintot = sum(a)
cnt = 1
for i in range(n):
  tot -= a[i]
  if a[i] <= tot*2:
    break
  cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
from itertools import accumulate
N = int( input())
A = list( map( int, input().split()))
A.sort()
l = -1
r = N-1
B = list( accumulate(A))
while r - l > 1:
    m = (l+r)//2
    # now = sum(A[:m+1])
    check = 1
    for i in range(m+1,N):
        if B[i] <= now*2:
            pass
        else:
            check = 0
            break
    if check == 1:
        r = m
    else:
        l = m
print(N-r)

Submission status: Runtime Error

Solution code:
N = int(input())
a = input().split()
for i in range(0,N):
	a[i] = int(a[i])
a.sort()
t = 0
flag = 1
sum_a = 0
for i in range(0,N):
	sum_a += a[i]
	if sum_a*2 < a[i+1]:
		t = i+1
		flag = 0
	if flag == 0:
		break
			
print(N-t)

Submission status: Runtime Error

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

s = 1
for i in range(n):
    a.sort()
    if 3*a[-1] <= 2*a[-2] or 3*a[-1] <= 2*sum(a):
        a.remove(a[-1])
        s = s + 1
    else:
        break
print(s)