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: Wrong Answer

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 a <= last/2:
        if idx!=leng-1 and sum(As[idx+1:])>=last/2:
            ret += 1
            d('\t',last,ret,leng,idx,a)
        else:
            d('\t',last,ret,leng,idx,a)
            pass
    else:
        d('\t',last,ret,leng,idx,a)
        ret += 1
    d('\t',last,ret,leng,idx,a)
    last = a
print(ret)

Submission status: Wrong Answer

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 a < last/2:
        if idx!=leng-1 and sum(As[idx+1:])>=last/2:
            ret += 1
            d('\t',last,ret,leng,idx,a)
        else:
            d('\t',last,ret,leng,idx,a)
            pass
    else:
        d('\t',last,ret,leng,idx,a)
        ret += 1
    d('\t',last,ret,leng,idx,a)
    last = a
print(ret)

Submission status: Wrong Answer

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:
            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) + 1

print(ans)

Submission status: Time Limit Exceeded

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

ans = n
for i in range(1,n):
    if a[i-1] <= 2*sum(a[i:]):
        pass
    else:
        print(i)
        exit()

print(n)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n=int(input())
    a=sorted(map(int,input().split()))
    cnt=0
    for i in range(n):
        c=a[i]
        for j in range(n):
            #print(f"c:{c} <> a:{a[j]}")
            if i == j:
                continue
            if 2*c < a[j]:
                break
            c += a[j]
        else:
            break
    return n-i
    
if __name__ == "__main__":
    print(main())

Submission status: Time Limit Exceeded

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

count = N
for i in range(N - 1, -1, -1):
    if sum(A[0:i]) * 2 >= A[i]:
        continue

    else:
        if (i == 0):
            continue
        count -= len(A[0:i])
        break

print(count)

Submission status: Time Limit Exceeded

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

# In[26]:


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


# In[27]:


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


# In[ ]:

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/agc011/tasks/agc011_b

import sys
input = sys.stdin.buffer.readline

n = int(input())
A = sorted([int(i) for i in input().strip().split()])
_max = A[-1]
cul_sum = [0] * (n + 1)

for i in range(1, n + 1):
    cul_sum[i] = cul_sum[i - 1] + A[i - 1]

ans = -1

cur = 0
ptr = cur
_tmp = cul_sum[ptr]
while True:
    _tmp += A[ptr]
    if _tmp * 2 >= _max:
        ans = cur
        break
    elif _tmp * 2 < A[ptr + 1]:
        cur += 1
        ptr = cur
        _tmp = cul_sum[ptr]
    else:
        ptr += 1

print(n - ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = list(map(int, input().split()))
a = sorted(A)
res = list(np.cumsum(a))

ans = 0
for i in range(len(res)):
    num = res[i]
    idx = i+1
    
    while(num*2 >= a[idx]):
        num += a[idx]
        idx += 1
        
        if(idx >= len(res)-1):
            break
       
    if(idx >= len(res)-1):
        print(N-i)
        break

Submission status: Time Limit Exceeded

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

result = [A[0]]
for i in A[1:]:
    result.insert(0,result[0] + i)
A.sort(reverse=True)
ans=1
for i in range(N-1):
    if result[i+1]*2 >= A[i]:
        ans+=1
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

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

result = [A[0]]
for i in A[1:]:
    result.insert(0,result[0] + i)
#print(result)
A.sort(reverse=True)
#print(A)
ans=1
for i in range(N-1):
    if result[i+1]*2 >= A[i]:
        ans+=1
    else:
        break
print(ans)

"""
for i in range(N):
    if flag == True:
        ans += N-i-1
        break
    Sum = sum(A[0:i+1])
    for j in range(i+1,N):
        if Sum*2 >= A[j]:
            Sum+=A[j]
            #print("i,j,Sum",i,j,Sum,ans)
            if j == N-1:
                ans += 1
                flag = True
print(ans+1)
"""

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
ans=0
flag = False
for i in range(N):
    if flag == True:
        ans += N-i-1
        break
    Sum = sum(A[0:i+1])
    for j in range(i+1,N):
        if Sum*2 >= A[j]:
            Sum+=A[j]
            #print("i,j,Sum",i,j,Sum,ans)
            if j == N-1:
                ans += 1
                flag = True
print(ans+1)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np 
n = int(input())
size_ls = list(map(int, input().split()))
size_ls.sort()
csum_size = list(np.cumsum(size_ls))

# とりあえず、与えられたインデックスの生き物が全部食べることをできるか返す関数
def isOK(start):
    res = True
    for i in range(start, n-1):
            if not 2 * csum_size[i] >= size_ls[i + 1]:
                res = False
                break
    return res

ans = 1
for i in range(n-1):
    if isOK(i):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())))
dp = {}
quota = 0
res = 0
baseSize = 0
for i in range(N-1):
  a = A[i]
  target = i+1
  baseSize += a
  size = baseSize
  while target < N and A[target] <= size*2:
    size += A[target]
    target += 1
  if target == N:
    res = target - i
    break

if res == 0:
  print(1)
else:
  print(res)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
d=[0]*n
d[0]=1

for i in range(1,n):
    if a[i]>2*sum(a[:i]):
        d[i]=1
    else:
        d[i]=d[i-1]+1
print(d[n-1])

Submission status: Time Limit Exceeded

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


# print(A)
t = 0
for k in range(1, n):
    # print("A[0:{}]={}".format(k, A[:k]))
    # print("{} <? {}".format(2 * sum(A[:k]), A[k]))
    if 2 * sum(A[:k]) < A[k]:
        t = max(t, k)

print(n - t)

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate

N = int(input())
A = list(map(int,input().split()))
A = sorted(A)
S = [0]+list(accumulate(A))
AS = [0]*N
count = 0
for i in range(N):
  AS[i] = A[i]+S[i]
for i in range(N):
  num = AS[i]
  for j in range(i+1,N):
    if num*2 >= A[j]:
      num += A[j]
      if j == N-1:
        ans = len(A)-count
        print(ans)
        exit()
    else:
      count += 1
      break

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate

N = int(input())
A = list(map(int,input().split()))
A = sorted(A)
S = [0]+list(accumulate(A))
count = 0

for i in range(N):
  num = A[i] + S[i]
  for j in range(i+1,N):
    if num*2 >= A[j]:
      num += A[j]
    else:
      count -= 1
      break
  count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import math

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

a.sort()

n1 = math.ceil(math.log(1000000000,2))+1

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

ans = 0
for i in range(n) :
  h = 0
  m = a[i]*2
  for j in range(n1) :
    mg = bisect.bisect_left(a,m)
    if mg <= n-1 and m == a[mg] :
      mg += 1
    m = s[mg-1]*2
    if m >= a[n-1] :
      ans += 1
      break
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import math

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

a.sort()

ans = 0
for i in range(n) :
  h = 0
  m = a[i]*2
  for j in range(math.ceil(math.log(1000000000,2))+1) :
    mg = bisect.bisect_left(a,m)
    if mg <= n-1 and m == a[mg] :
      mg += 1
    m = sum(a[:mg])*2
  if mg >= n :
    ans += 1
  
print(ans)

Submission status: Time Limit Exceeded

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

tmp = 0
sum_a = sum(A)
ind = N+1
for i in range(N-1):
    #tmp += A[i]*2
    tmp = 2*sum(A[:i+1])
    if tmp < A[i+1]:
        ind = i

if ind == N+1:
    print(N)
else:
    print(N-ind-1)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 1
for i in range(len(a) - 1, -1, -1):
    if sum(a[:i]) * 2 < a[i]:
        break
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=0
ai_sum=0
for i in range(n):
    ai_sum+=a[i]
    clear=True
    scale=ai_sum
    for j in range(i+1,n):
        if(2*scale>=a[j]):
            scale+=a[j]
        else:
#            print(i,j,scale)
            i=j
            clear=False
            break

    if(clear):
        ans=n-i
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=0
ai_sum=0
for i in range(n):
	ai_sum+=a[i]
	clear=True
	scale=ai_sum
	for j in range(i+1,n):
		if(2*scale>=a[j]):
			scale+=a[j]
		else:
#			print(i,j,scale)
			clear=False
			break
	
	if(clear):
		ans=n-i
		break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=0
for i in range(n):
	a_bkup=a
	ai=a[i]
	clear=True
	scale=0
	for j in range(n):
		if(j<=i):
			scale+=a[j]
		elif(2*scale>=a[j]):
			scale+=a[j]
		else:
#			print(i,j,scale)
			clear=False
			break
	
	if(clear):
		ans=n-i
		break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
a = list(map(int,input().split()))
a.sort()
#print(a)[1, 2, 7, 20, 30, 40]
A = list(itertools.accumulate(a))
#print(A)
cnt = 1
for i in range(n-1):
  s = A[i]
  #print(s)
  for j in range(i+1,n):
    if s*2 >= a[j] :
      s += a[j]
      #print(s)
    else:
      break
  if s == A[-1]:
    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
cnt = 1
for i in range(n-1):
  s = sum(a[:i+1])
  #print(s)
  for j in range(i+1,n):
    if s*2 >= a[j] :
      s += a[j]
      #print(s)
    else:
      break
  if s == sum(a):
    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = sorted(list(map(int, input().split())))
c = 1
for i in range(n-1, 0, -1):
  if sum(A[:i]) >= (A[i]+1)//2:
    c += 1
  else:
    print(c)
    exit()
print(n)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = sorted(list(map(int, input().split())))
c = 1
for i in range(n-1, 0, -1):
  if sum(A[:i])*2 >= A[i]:
    c += 1
  else:
    print(c)
    exit()
print(n)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)
start_i=0
end=False
#print(a)
while(not end):
    max_a=a[start_i]
    for i in range(start_i,n):
        if(max_a>2*sum(a[i:])):
            if(start_i==i-1):
                end=True
            else:
                start_i=i-1
            break
        if(i==n-1):
            start_i=i
            end=True
#    print(start_i)
print(start_i+1)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
A.sort()
ans=0

l=[A[0]]
for i in range(1,len(A)+1):
    l.append(sum(A[0:i+1]))
    if (l[i]-l[i-1])>2*l[i-1]:
        ans=0
    else:
        ans+=1

print(ans)

Submission status: Time Limit Exceeded

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

cnt=1

for i in range(1,N):
    a=min(A)
    A.remove(min(A))
    b=min(A)
    A.remove(min(A))
    if 2*a>=b:
        cnt+=1
    else:
        cnt=1
    A.append(a+b)

print(cnt)

Submission status: Time Limit Exceeded

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

A.sort(reverse=True)

cnt=1

for i in range(1,N):
    a=A.pop()
    b=A.pop()
    if 2*a>=b:
        cnt+=1
    else:
        cnt=1
    A.append(a+b)
    A.sort(reverse=True)

print(cnt)

Submission status: Time Limit Exceeded

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
	for i in range(N):
		if (sum(a)-sum_list[i])*2 >= a[i]:
			count += 1
		else:
			break

	print(count)

if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
#逆順にしてはやめにbreakできるように
N=int(input())
A=sorted(map(int,input().split()),reverse=True)
c=0
for n in range(N-1):
  if sum(A[n+1:])*2 >= A[n]:
    c+=1
  else:
    break
print(c+1)

Submission status: Time Limit Exceeded

Solution code:
#累積和のリストを作らない
N=int(input())
A=sorted(map(int,input().split()))
c=0
for n in range(N-1):
  if sum(A[:n+1])*2 >= A[n+1]:
    c+=1
  else:
    c=0
print(c+1)

Submission status: Time Limit Exceeded

Solution code:
#10:30〜10:46 再提出
N=int(input())
A=sorted(map(int,input().split()))
B=[]
for n in range(N):
  B.append(sum(A[:n+1]))
c=0
for n in range(N-1):
  if B[n]*2 >= A[n+1]:
    c+=1
  else:
    c=0
print(c+1)

Submission status: Time Limit Exceeded

Solution code:
#10:30〜10:46
#A.sort()
#1 2  7 20 30  40
#累積和=B
#1 3 10 30 60 100
#下克上可能か判定
#if B[i]*2 >= A[i+1] なら下克上可能　1をappend
#else 不可能 0をappend
#下克上可能リスト（=C）
#10111
#最後に出現した0以降の1の個数をカウント：c
#そして+1する
N=int(input())
A=sorted(map(int,input().split()))
B=[]
for n in range(N):
  B.append(sum(A[:n+1]))
c=0
for n in range(N-1):
  if B[n]*2 >= A[n+1]:
    c+=1
  else:
    c=0
print(c+1)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
arr = map(int,raw_input().split())
arr.sort()
cnt = 0

for i in range(1,n):
	if sum(arr[:i])*2 < arr[i]:
		cnt = i

print n-cnt

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

A = sorted(list(map(int,input().split())))
B = [sum(A[:i+1]) for i in range(N)][::-1]
A.reverse()

min_abs = A[0]
ans = 1
for i in range(1,N):
    if A[i]*2 >= min_abs:
        ans += 1
    elif B[i]*2 >= min_abs:
        ans += 1
    else:
        break
    min_abs = A[i]
    
print(ans)

Submission status: Time Limit Exceeded

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

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

# N-1 .. 0
cnum = 1
for i in range(N-1,0,-1):
    #print(A[:i])
    #print(A[i])
    if sum(A[:i]) * 2 < A[i]:
        break
    else:
        cnum += 1
print(cnum)

Submission status: Time Limit Exceeded

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

F = np.ones(N, np.int)
for i in range(N):
    FLAG = False
    for j in range(i,N-1):
        if 2*S[j] < A[j+1]:
            FLAG=True
            break
    if FLAG:
        F[i] = 0
    else:
        break

print F.sum()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

C = range(N)
A.sort()

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

F = np.ones(N, np.int)
for i in range(N):
    FLAG = False
    for j in range(i,N-1):
        if 2*S[j] < A[j+1]:
            FLAG=True
            break
    if FLAG:
        F[i] = 0

print F.sum()

Submission status: Time Limit Exceeded

Solution code:
def main():
	num_creatures = int(input()) #num of creatures
	tmp = input().split(' ')
	size_creatures = [] 

	for i in tmp:
		size_creatures.append(int(i))

	size_creatures.sort()
	counter = 0
	#checking available to be last one
	for index,value in enumerate(size_creatures):
		size = value
		for i in size_creatures[:index]:
			size += i
		for i in size_creatures[index+1:]:
			if i <= (size*2):
				size += i
			else:
				break
		else:
			counter += 1

	print(counter)

if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

Solution code:

def main():
	num_creatures = int(input()) #num of creatures
	tmp = input().split(' ')
	size_creatures = [] 

	for i in tmp:
		size_creatures.append(int(i))

	#checking available to be last one
	counter = 0
	for index,value in enumerate(size_creatures):
		rslt = check_available_lastone(size_creatures, index)
		if rslt == 1:
			counter += 1
		elif rslt == 0:
			continue

	print(counter)


def check_available_lastone(size_creatures, index):
	list_creatures = list(size_creatures)
	creature = size_creatures[index]
	list_creatures.pop(index)

	while(1):
		flag = False
		if len(list_creatures) == 0:
			return 1

		for itr, size in enumerate(list_creatures):
			if size <= (creature*2):
				creature += size
				list_creatures.pop(itr)
				if not flag:
					flag = True
			else:
				continue

		if flag:
			continue
		elif not flag:
			return 0
		
if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

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

counter = 0

for ind, cre in enumerate(l_cre):
    now_size = 0
    now_size += sum(l_cre[:(ind + 1)])
    rest_cre = len(l_cre) - ind - 1

    while True:
        if (ind + 1) == len(l_cre):
            counter += 1
            break

        ind += 1
        if (now_size * 2) >= l_cre[ind]:
            now_size += l_cre[ind]
            continue
        else:
            break

print(counter)

Submission status: Time Limit Exceeded

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

for i in range(n-1):
    small = sum(a[0:i+1])
    if 2 * small < a[i+1] and i != n-1:
        flag = i + 1

print(n-flag)

Submission status: Time Limit Exceeded

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

    A.sort()

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

main()

Submission status: Time Limit Exceeded

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

    A.sort()
    A.reverse()

    i = 1
    j = 1
    while j < N:
        if A[j - 1] / 2 <= sum(A[j:]):
            i += 1
        else:
            break
        j += 1
    print(str(i))

main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N=int(input())
count = 0
B = list(map(int,input().split()))
A=np.array(B)
count=0
A=np.sort(A)
for i in range (N):
    j=0
    co=0
    a=A[i]
    for j in range(i):
        a+=A[j]
    j=1
    while(1):
        if i+j>=N:
            count+=1
            break
        if 2*a>=A[i+j]:
            a+=A[i+j]
        else:
            break
        j+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(raw_input())
count = 0
A = list(map(int,raw_input().split()))
count=0
A.sort() 
B = list(A)
for i in range (N):
    j=0
    co=0
    re=0
    A=list(B)
    for j in range(i):
        A[i]+=A[j]
    j=1
    while(1):
        if i+j>=N:
            count+=1
            break
        if 2*A[i]>=A[i+j]:
            A[i]=A[i]+A[i+j]
        else:
            break
        j+=1
            
print(count)

Submission status: Time Limit Exceeded

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

a = sorted(a)

f = True
c = 0
for i in reversed(range(len(a))):
    s = a[i]
    for j in range(len(a)):
        if i == j:
            continue
        if s * 2 >= a[j]:
            s += a[j]
        else:
            f = False
            break

    if f == False:
        break
    c += 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
N=int(raw_input())
count = 0
A = list(map(int,raw_input().split()))
count=0
B = list(A)
for i in range (N):
    j=0
    co=0
    re=0
    A=list(B)
    while(1):
        if re>=N-1:
            count+=1
            break
        if co>=N:
            break
        if i!=j%N:
            if 2*A[i]>=A[j%N] and A[j%N]!=0:
                A[i]=A[i]+A[j%N]
                A[j%N]=0
                co=0
                re+=1
            else:
                co+=1
        j+=1
            
print(count)

Submission status: Time Limit Exceeded

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

s = 1
for i in range(n):
    if 3*max(a) > 2*sum(a):
        break
    else:
        a.remove(max(a))
        s += 1
print(s)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
count = 0
A = list(map(int,input().split()))
count=0
B = list(A)
for i in range (N):
    j=0
    co=0
    re=0
    A=list(B)
    while(1):
        if re>=N-1:
            count+=1
            break
        if co>=N:
            break
        if i!=j%N:
            if 2*A[i]>=A[j%N] and A[j%N]!=0:
                A[i]=A[i]+A[j%N]
                A[j%N]=0
                co=0
                re+=1
            else:
                co+=1
        j+=1
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
m = int(input())
n = list(map(int,input().split()))
ans = 0
for i in range(len(n)):
    ncopy = list(n)
    child = ncopy[i]
    ncopy.remove(ncopy[i])
    while(True):
        if len(ncopy) == 0:
            ans += 1    
        start = list(ncopy)
        for k in ncopy:
            if k <= child*2:
                ncopy.remove(k)
                child += k
        end = list(ncopy)
        if start == end:
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted(map(int, input().split()), reverse=True)

color_patterns = 0
for i, a in enumerate(A):
    creature = a + sum(A[i + 1:])
    target_i = i - 1
    while target_i >= 0 and creature * 2 >= (A[target_i]):
        creature += A[target_i]
        target_i -= 1
    if target_i < 0:
        color_patterns += 1
print(color_patterns)

Submission status: Accepted

Solution code:
from itertools import accumulate


N, *A = map(int, open(0).read().split())
A.sort()
acc = list(accumulate(A))
ans = N
for i in range(N - 1):
    if 3 * acc[i] < acc[i + 1]:
        ans = N - i - 1
print(ans)

Submission status: Accepted

Solution code:
import sys
stdin=sys.stdin

ip=lambda: int(sp())
fp=lambda: float(sp())
lp=lambda:list(map(int,stdin.readline().split()))
sp=lambda:stdin.readline().rstrip()

n=ip()
a=lp()

a.sort()

rui=[0]

for i in range(n):
  rui.append(rui[-1]+a[i])
  
ch=1

rui.sort(reverse=True)

for j in range(n):
  if rui[j]<=rui[j+1]*3:
    ch+=1
  else:
    break
print(ch)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
al = sorted(list(map(int, input().split())))
c = list(np.cumsum(al))

ans = 1
for i in range(n-1):
    if c[i]*2 >= al[i+1]:
        ans += 1
    else:
        ans = 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort()
from itertools import accumulate
C = [0]+A
C = list(accumulate(C))

def is_ok(x):
    if x < 0:
        return False
    cur = C[x+1]
    for i in range(x+1, n):
        if A[i] <= 2*cur:
            cur += A[i]
        else:
            break
    else:
        return True
    return False

ng = -1
ok = n-1
while ng+1 < ok:
    c = (ok+ng)//2
    if is_ok(c):
        ok = c
    else:
        ng = c

ans = n-ok
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
sa = sorted(a)
r = []
# ruiseki
su = 0
for i in range(n):
  su += sa[i]
  r.append(su)
ans = 1

for i in range(n-1):
  if (r[~i-1]*2 >= sa[~i]):
    ans += 1
  else:
    break
print(ans)

Submission status: Accepted

Solution code:
import heapq
N = int(input())
A = sorted(list(map(int,input().split())))
heap = []
for i in range(N):
    a = A[i]
    heapq.heappush(heap,(a,1))
while len(heap)>1:
    a,n1 = heapq.heappop(heap)
    b,n2 = heapq.heappop(heap)
    if b<=2*a:
        a += b
        heapq.heappush(heap,(a,n1+n2))
    else:
        a += b
        heapq.heappush(heap,(a,n2))
a,n = heapq.heappop(heap)
print(n)

Submission status: Accepted

Solution code:
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, A):
    A.sort()
    s = 0
    dp = [0] * (N + 1)
    for i, a in enumerate(A):
        dp[i + 1] = 1
        if a <= s * 2: dp[i + 1] += dp[i]
        s += a
    print(dp[N])

if __name__ == '__main__':
    input = sys.stdin.readline
    N = int(input())
    *A, = map(int, input().split())
    main(N, A)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
A = list(map(int, input().split()))
A.sort()
AA = list(itertools.accumulate(A))
for i in range(N-1):
  if AA[N-2-i]*2 < A[N-1-i]:
    print(i+1)
    exit()
print(N)

Submission status: Accepted

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

a.sort()

c = 0
s = []
for i in range(n):
  c+=a[i]
  s.append(c)
ng = 0
for i in range(1,n):
  if a[i] > 2*s[i-1]:
    ng = i
print (n-ng)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
sm = 0
r = [0]*n
r[0]=a[0]
for i in range(1,n):
    if r[i-1]*2 >= a[i]:
        sm += 1
    else:
        sm = 0
    r[i] = r[i-1] + a[i]

print(sm+1)

Submission status: Accepted

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

A.sort()
ans = 1

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

print(ans)

Submission status: Accepted

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

A = sorted(A)

wa = A[0]  # i - 1 までの和
cnt = 1  # i 番目の生き物の 2 倍より小さかったのに、i 番目の生き物を食べれるやつの数
for i in range(1, N):
    if 2 * wa >= A[i]:
        cnt += 1
    else:
        cnt = 1
    wa += A[i]
print(cnt)

Submission status: Accepted

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

ans = 1
for i in range(N - 2, -1, -1):
    if A[i + 1] <= 2 * B[i]:
        ans += 1
    else:
        break

print(ans)

Submission status: Accepted

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

# 累積和取る。
for i in range(1, n):
  A[i] += A[i - 1]

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

Submission status: Accepted

Solution code:

def resolve():
    N = int(input())
    A = sorted(map(int, input().split()))

    idx = 0
    tmp = 0
    for i in range(N):
        if tmp * 2 < A[i]:
            idx = i
        tmp += A[i]

    print(N - idx)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

ans = n
for i in range(1,n):
    sum_a -= a[i-1]
    if a[i-1] <= 2*sum_a:
        pass
    else:
        print(i)
        exit()

print(n)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    cum = 0
    t = 0
    for i in range(N-1):
        cum += A[i]
        if 2*cum < A[i+1]:
            t = i+1
    ans = N - t
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from itertools import accumulate
n = int(input())
a = list(map(int, input().split()))
a.sort()
asum = list(accumulate(a))

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