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:
n = int(input())
a = list(map(int, input().split()))

a.sort()
s = [0 for _ in range(n)]
s[0] = a[0]

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

def find(a, x):
    u, l = len(a), -1
    
    while u > l+1:
        md = (u+l) // 2
        if x >= a[md]:
            l = md
        else:
            u = md
    return u - 1      

ans = [0 for _ in range(n)]
for i in range(n):
    cur = i 
    nx  = find(a, s[i])
    while nx != cur:
        cur = nx
        nx  = find(a, s[nx])
    ans[i] = nx
    
count = 0    
for x in ans:
    if x == len(a) - 1:count+=1
print(count)

Submission status: Accepted

Solution code:
a = int(input())
x=list(map(int,input().split()))
import itertools
x.sort()
c=list(itertools.accumulate(x))
s = 0
c=c[::-1]
x = x[::-1]
#print(c)
#print(x)
for i,(t,l) in enumerate(zip(c[1:],x[:-1])):
    #print(t,l)
    if t*2 >= l  :s+=1
    else:break
print(s+1)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

from itertools import accumulate

def main():
    N = II()
    A = LI()
    A.sort()
    S = list(accumulate(A))
    ans = 1
    for s, a in zip(S[-2::-1], A[-1::-1]):
        if s * 2 < a:
            break
        ans += 1

    return ans

print(main())

Submission status: Accepted

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

Submission status: Accepted

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

def io_generator():
	return input()

#+++++++++++++++++++

def main(io):
	a=int(io())
	l = list(map(int, io().split()))
	
	l.sort(reverse=True)
	m=sum(l[1:])
	pre=l[0]
	num=1
	for val in l[1:]:
		if pre > m*2:
			break
		else:
			num+=1
			pre=val
			m=m-val
		
	return num

#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	print (main(io))

Submission status: Accepted

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

b = []
c = 0
for i in range(n):
    c += a[i]
    b.append(c)
a.sort(reverse=True)
b.sort(reverse=True)

d = 0
for i in range(1,n):
    if b[i]*2 < a[i-1]:
        d = i
        break
        
if d:
    print(d)
else:
    print(n)

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    A = LI()
    A.sort()

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

    t = 0
    for i, (a, c) in enumerate(zip(A[1:], C[1:-1])):
        # 1~kまでのサイズの和の2倍がk+1番目の生き物のサイズ未満なら1~kは最後まで生き残れない
        if a > 2 * c:
            t = i + 1

    return n - t


print(main())

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(map(int,input().split()))
ruiseki = [0]
for i in range(n):
    ruiseki.append(ruiseki[-1]+a[i])
ruiseki = ruiseki[1:]

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

Submission status: Accepted

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

a.sort()

# 累積和は0を含んだ0-basedの半開区間でかく(1-indexed)
acum = [0] * (n+1)
for i in range(n):
    acum[i+1] += acum[i] + a[i]

ans = 1  # i = n-1 の時は必ず全て取り込めるので省いておく

for i in reversed(range(n-1)):
    if a[i+1] <= 2 * acum[i+1]:
        ans += 1
    else:
        break

print(ans)

Submission status: Accepted

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

a.sort()
acum = [0] * (n+1)

# 累積和は0を含んだ0-basedの半開区間でかく(1-indexed)
for i in range(n):
    acum[i+1] += acum[i] + a[i]

ans = 1  # i = n-1 の時は必ず全て取り込めるので省いておく

for i in reversed(range(n-1)):
    if a[i+1] <= 2 * acum[i+1]:
        ans += 1
    else:
        break

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
t=sorted(map(int, input().split()),reverse=True)
sm=sum(t)
ans=0
for i in t:
    sm-=i
    ans+=1
    if i>sm*2:
        break
print(ans)

Submission status: Accepted

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

a.sort()
acum = [0] * (n+1)
for i in range(n):
    acum[i+1] += acum[i] + a[i]

ans = 1

for i in reversed(range(1, n)):
    if a[i] <= 2 * acum[i]:
        ans += 1
    else:
        break

print(ans)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from itertools import accumulate

n = ni()
a = list(li())
a.sort()
acc = list(accumulate(a))



ans = 0
for ai, acci in zip(a[-1:0:-1], acc[-2::-1]):
    if 2*acci >= ai:
        ans += 1
    else:
        break
        
        
print(ans+1)

Submission status: Accepted

Solution code:
def inpl(): return list(map(int, input().split()))
N = int(input())
A = sorted(inpl())
tmp = 1
size = A[0]
for a in A[1:]:
    tmp = tmp * (a <= 2*size) + 1
    size += a
print(tmp)

Submission status: Accepted

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

c = 0
kind = N
for i,a in enumerate(A):
    if c*2 < a:
        kind = N - i
    c += a
print(kind)

Submission status: Accepted

Solution code:
import bisect

n = int(input())
a = sorted(list(map(int, input().split())))
a_t = [0]
for i in range(n):
    a_t.append(a[i] + a_t[i])
a_t = a_t[1:]
ans = 0
mi = 0
for i in range(n):
    index = bisect.bisect_right(a, a[i] * 2) - 1
    if index == n - 1:
        if not mi:
            mi = i
for i in range(n - 1, -1, -1):
    index = bisect.bisect_right(a, a_t[i] * 2) - 1
    if index >= mi:
        mi = i
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

ans = N

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

Submission status: Accepted

Solution code:
from itertools import accumulate
n=int(input())
A=list(map(int,input().split()))
A.sort()
S=list(accumulate(A))
cnt=1
for i in range(n-1):
    if 3*S[i]>=S[i+1]:
        cnt+=1
    else:
        cnt=1
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
preS = sum(A[:-1])
num = 0
for i in range(N - 1, 0, -1):
    if 2 * preS < A[i]:
        num = i
    else:
        preS -= A[i - 1]
print(N - num)

Submission status: Accepted

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 A[i] <= B[i-1]*2:
            pass
        else:
            check = 0
            break
    if check == 1:
        r = m
    else:
        l = m
print(N-r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
n = int(input())
a = [int(m) for m in input().split()]
a.sort()
acculi = list(itertools.accumulate(a))
sym = -1
for i in range(n - 1):
    if 2 * acculi[i] < a[i + 1]:
        sym = i
print(n - sym - 1)

Submission status: Accepted

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
ar.sort()
count = a
total = ar[0]
b = 1
for i in range(1,a):
    if total * 2 < ar[i]:
        count -= b
        b = 0
    b += 1
    total += ar[i]
print(count)

Submission status: Accepted

Solution code:
from itertools import accumulate

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

check = [False for _ in range(N)]

acc = tuple(accumulate(a_list))

for i in range(N - 1):
    if acc[i] * 2 >= a_list[i + 1]:
        check[i] = True
check[N - 1] = True

ans = 0
for c in check:
    if c:
        ans += 1
    else:
        ans = 0
print(ans)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
A = sorted([int(_) for _ in input().split()])
cumsum = list(itertools.accumulate(A))
ans = N
for i in range(1, N):
    if A[-i] > 2 * cumsum[-i - 1]:
        ans = i
        break
print(ans)

Submission status: Accepted

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

a.sort()
cant = 0
for i in range(len(a)):
    if i==0:
        s=a[i]
        continue
    if(s*2<a[i]):
        cant = i
    s += a[i]
print(n-cant)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
A.sort(key=lambda x:-x)
S=[0]
for i in range(N):
  S.append(S[i]+A[i])
ans=1
for i in range(1,N):
  if A[i-1]<=2*(S[N]-S[i]):
    ans+=1
  else:
    break
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
A.sort()
SumA = [0]
for i in range(N):
    SumA.append(SumA[-1] + A[i])

def DS(i, a, b, L = list):
    lower, higher = a, b
    while higher - lower > 1:
        mid = (lower + higher)//2
        if L[mid] > i: higher = mid
        else: lower = mid
    return lower

Ans = 1
for i in reversed(range(N-1)):
    lim = DS(A[i]*2, i, N, A)
    if lim == N-1: Ans += 1
    elif 2 * (SumA[lim+1] - SumA[0]) >= A[lim+1]: Ans += 1
    else: break

print(Ans)

Submission status: Accepted

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

#累積和b[i]:a[0]~a[i]
b = [a[0]]
for i in range(1,n):
    b.append(b[-1]+a[i])

res = 0
for i in range(1,n):
    if a[i] > b[i-1]*2:
        res = i

print(n-res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def inpl(): return [int(i) for i in input().split()]
import numpy as np

N = int(input())
A = np.sort(np.array(inpl()))
B = np.cumsum(A)

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

print(ans+1)

Submission status: Accepted

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

total_size = 0
muri = 0
for i,size in enumerate(A):
    if total_size*2 < size:
        muri = i
    total_size += size
print(N - muri)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
if N == 2:
	if A[0] * 2 >= A[1]:
		print(2)
	else:
		print(1)

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

	c += 1
	print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = sorted([int(x) for x in input().split()])

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

if k==-1:
    print(n)
else:
    print(n-k-1)

Submission status: Accepted

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

As.sort()

accA = sum(As[:-1])
for i in reversed(range(N - 1)):
    if accA * 2 < As[i + 1]:
        print(N - 1 - i)
        break
    accA -= As[i]
else:
    print(N)

Submission status: Accepted

Solution code:
n=input()
a=map(int, raw_input().split())
a.sort()
result=-1
sum=0
for cur in a:
	if sum*2<cur:
		result=0
	result+=1
	sum+=cur
print result

Submission status: Accepted

Solution code:
def getN():
    return int(input())


def getNM():
    return map(int, input().split())


def getList():
    return list(map(int, input().split()))

N = getN()
size = getList()

size.sort()

acc = 0
lim = 0
for i, si in enumerate(size[:-1]):
    acc += si
    if acc*2 < size[i+1]:
        lim = i+1

print(N-lim)

Submission status: Accepted

Solution code:
n = int(input())

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

ans = n
size = a[0]
count = 1
for i in range(1, n):
    if a[i] > size * 2:
        count = 1
    else:
        count += 1
    size += a[i]

print(count)

Submission status: Accepted

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

B=[0]
for i in range(N):
    B.append(B[i]+A[i])
#print(B)
ans=1
for j in range(N):
    if B[j]*3<B[j+1]:
        ans=1
    else:
        ans+=1
        
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(map(int,input().split()))
s=t=0
for i in range(n-1):
    s+=a[i]
    if s*2<a[i+1]:
        t=i+1
print(n-t)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(map(int, input().split()))
ans = 1
s = 0
for i in range(N - 1):
    s += A[i]
    if 2 * s < A[i + 1]:
        ans = 1
    else:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

from itertools import accumulate

n = ni()
a = li()

a.sort()
a_cum = list(accumulate(a))[::-1]
a.sort(reverse=True)

ans = n

for i in range(n-1):
    if a[i] <= 2*a_cum[i+1]:
        continue
    else:
        ans = i+1
        break
        
print(ans)

Submission status: Accepted

Solution code:
f = lambda: map(int,input().split())
n = int(input())
a = sorted(list(f()))
s = [a[0]]
for i in range(n-1):
    s.append(s[-1]+a[i+1])
ans = 1
for i in range(2,n+1):
    if s[-i]*2<a[-i+1]:
        break
    ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
a_sum = [a[0]]
for i in range(1, n):
	a_sum.append(a_sum[-1] + a[i])

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

print(n - max_ng - 1)

Submission status: Accepted

Solution code:
n=int(input())
o=sorted(map(int,input().split()))
v=0
k=0
for i in range(n-1):
  v+=o[i]
  if v*2<o[i+1]:
    k=i+1
print(n-k)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
N = int(input())
A = sorted(inpl())

ans = 1
tmp = A[0]

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

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
aa = inpl()
aa.sort()

tmp = 0
SUM_aa = [0]
for a in aa:
	tmp += a
	SUM_aa.append(tmp)

def solve(ind):
	size = SUM_aa[ind]
	b_ind = ind

	while True:
		ind = bisect.bisect_right(aa,size*2)

		if ind == N:		#全部吸収
			return True
		elif b_ind == ind:	#ind変更なし
			return False

		size = SUM_aa[ind]
		b_ind = ind

NG = 0
OK = N

while OK-NG > 1:
	mid = (OK+NG)//2
	if solve(mid):
		OK = mid
	else:
		NG = mid

print(N-OK+1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    A.sort()
    sa = [0]
    for a in A:
        sa.append(sa[-1] + a)

    b = []
    for i in range(N-1):
        if 2*sa[i+1] >= A[i+1]:
            b.append(True)
        else:
            b.append(False)
    b.append(True)

    ans = 0
    for c in b[::-1]:
        if c:
            ans += 1
        else:
            break
    return ans


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())

arr = map(int,raw_input().split())
arr.sort()
cs = np.cumsum(arr)

ans = 1

i = n-2
while i > -1 and cs[i] * 2 >= arr[i+1]:
	ans += 1
	i -= 1

print ans

Submission status: Accepted

Solution code:
n = input()
v = map(int, raw_input().split(' '))
v.sort()

def good(mid, v):
	sum = v[mid]
	for i in range(n):
		if i != mid:
			if v[i] > 2 * sum:
				return False

			sum += v[i]

	return True


l, r = 0, n - 1
best = n - 1

while l <= r:
	mid = (l + r) / 2

	if good(mid, v):
		best = mid
		r = mid - 1
	else:
		l = mid + 1

print n - best

Submission status: Accepted

Solution code:
import bisect


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

    a.sort()
    a2 = a[::-1]

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

    ans, max_s = 0, a2[0]
    for i in range(n):
        t = sa[bisect.bisect_right(a, 2*a2[i])]
        if max_s <= 2 * t:
            ans += 1
            max_s = a2[i]
        else:
            break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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-1):
	sum_a += a[i]
	if sum_a*2 < a[i+1]:
		t = i+1

			
print(N-t)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(_) for _ in input().split()]

A.sort()

result = 0
t = 0

for a in A:
    if a <= t * 2:
        t += a
        result += 1
    else:
        t += a
        result = 1

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate

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

A.sort()
S=list(accumulate(A))
S.sort(reverse=True)
A.sort(reverse=True)

ans=1

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

print(ans)

Submission status: Accepted

Solution code:
import sys

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


res = 1
s = sum(A[0:N-1])
i = N - 2
while i >=0:
    if A[i + 1] <= 2 * A[i]:
        res += 1
        s -= A[i]
    else:
        if A[i + 1] <= 2 * s:
            res += 1
            s -= A[i]
        else:
            i = -1
        
    i -= 1
print(res)

Submission status: Accepted

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

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(input())
    an = list(map(int, input().split()))
    an = sorted(an)
    assert len(an) == n
    bn = [an[0]]
    for i in range(1, n):
        bn.append(bn[-1] + an[i])

    cuts = []
    for i in range(n - 1):
        if bn[i] * 2 < an[i + 1]:
            cuts.append(i + 1)

    maxj = max(cuts + [0])
    assert 0 <= maxj < n
    print(n - maxj)

main()

Submission status: Accepted

Solution code:
n = int(input())
creatures = list(map(int,input().split()))
creatures.sort()
ans = 0
p = creatures[0]
for i in range(1, n):
    if creatures[i] > p * 2:
        ans = 0
    else:
        ans += 1
    p += creatures[i]
ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

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

Submission status: Accepted

Solution code:
from copy import deepcopy


def read():
    return int(input())


def readlist():
    return list(map(int, input().split()))

def readmap():
    return map(int, input().split())


N = read()
A = readlist()
A.sort()

Acum = deepcopy(A)

for i in range(1, N):
    Acum[i] += Acum[i-1]

ans = 0
for i in reversed(range(N)):
    if i == N-1:
        ans += 1
    elif 2 * Acum[i] >= A[i+1]:
        ans += 1
    else:
        print(ans)
        quit()
print(N)

Submission status: Accepted

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

r=0
b=[]
for i in a:
  r+=i
  b.append(r)
ans=1

  
b.sort(reverse=True)
a.sort(reverse=True)

for i in range(1,n):
  if b[i] * 2 >=a[i-1]:
    ans+=1
  else:
    break

print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
b,c = [a[0]],[False for i in range(n)]
for i in range(1,n): b.append(b[-1]+a[i])
for i in range(n-1,-1,-1):
	x = bisect_left(a,b[i]*2+0.5)
	if x==n: c[i] = True
	elif c[x-1]: c[i] = True
print(sum(c))

Submission status: Accepted

Solution code:
import sys
import numpy as np

import sys

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    A = []
    input_raw = read_func().strip().split()
    for i in range(N):
        A.append(int(input_raw[i]))

    A.sort(reverse = True)
    sum_A = [0 for i in range(N)]
    for i in range(N-1, -1, -1):
        if i == N - 1:
            sum_A[i] = A[i]
        else:
            sum_A[i] = A[i] + sum_A[i + 1]


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

    print count

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())))
cumA = [0]
for a in A:
    if a > 2*cumA[-1]:
        t = A.index(a)
    cumA.append(cumA[-1] + a)
print(N-t)

Submission status: Accepted

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

left = 0
right = N
for i in range(int(math.log(N, 2)) + 10):
    center = (left + right) // 2
    B = A[:center] + A[center+1:]
    slime = A[center]

    for b in B:
        if 2*slime >= b:
            slime += b
        else:
            left = center
            break
    else:
        right = center

print(N - right)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)
A_SUM = sum(A)
count = 1
for i in A:
    A_SUM -= i
    if 2*A_SUM >= i:
        count += 1
    else:
        break
print(count)

Submission status: Accepted

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

k = s = 0
for i,a in enumerate(src):
    if 2*s < a:
        k = i
    s += a
print(N - k)

Submission status: Accepted

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

#print(xs)
acc = [0]
for i in range(n):
    acc.append(acc[-1] + xs[i])
#print(acc)

ans = 1
for i in range(n-2,-1,-1):
    if acc[i+1] * 2 >= xs[i+1]:
        ans += 1
    else: break
print(ans)

Submission status: Accepted

Solution code:
n = int(raw_input())

v = map(int, raw_input().split(' '))
v.sort()

sum = 0

res = n

for i in range(n):
	if 2 * sum < v[i]:
		res = n - i
	sum += v[i]
	
print res

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
m = [[a for i in range(2)] for j in range(n)]
sum=0
count=1
a.sort()
for i in range(n):
 m[i][0]=a[n-i-1]
 sum=sum+a[i]
 m[n-i-1][1]=sum

for i in range(n-1):
  if 2*m[i+1][1]>=m[i][0]:
     count=count+1
  else:
     break

print(count)

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")

def ok(idx, a_list):
    now = a_list[idx]
    for i in range(len(a_list)):
        if i == idx:
            continue
        else:
            if a_list[i] > now * 2:
                return False
            now += a_list[i]
    return True


def main():
    N = int(input())
    a_list = sorted(list(map(int, input().split())))

    # [low, high)
    low, high, ans = -1, N, -1
    while high - low > 1:
        middle = (low + high) // 2
        if ok(middle, a_list):
            ans = middle
            high = middle
        else:
            low = middle

    print(N - ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,a=int(input()),sorted(list(map(int,input().split())))
lb,ub=-1,n
def check(mid):
	sz=a[mid]
	for i in range(n):
		if i==mid: continue
		if 2*sz>=a[i]: 
			sz+=a[i]
		else:
			return False
	return True
while ub-lb>1:
	mid=(lb+ub)//2
	if check(mid):
		ub=mid
	else:
		lb=mid
print(n-ub)

Submission status: Accepted

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

Submission status: Accepted

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

count = 0
total_size = creature_states[0]

for i in range(1, n):
  if creature_states[i] <= total_size * 2:
    count += 1
  else:
    count = 0
  total_size += creature_states[i]

print(count + 1)

Submission status: Accepted

Solution code:
n = int(raw_input())
l = map(int, raw_input().split())
l.sort()
l.reverse()
s = sum(l)
cnt = 1
for v in l:
    s -= v
    if v <= s*2:
        cnt += 1
    else:
        break
print cnt

Submission status: Accepted

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

res = 0
cur = 0
for i in xrange(len(arr) - 1):
	cur += arr[i]
	res += 1
	if not (arr[i+1] <=  2 * cur):
		res = 0

print res + 1

Submission status: Accepted

Solution code:
def smallestPossible(creatures):
	creatureSum = 0
	possible = 0
	for i in range(len(creatures)):
		if i == len(creatures) - 1:
			return possible + 1
		creatureSum += creatures[i]
		if (2 * creatureSum >= creatures[i + 1]):
			possible += 1
		else:
			possible = 0

input()
print(smallestPossible(sorted(list(map(lambda x: int(x), input().split())))))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

res = 1
for i in reversed(range(0, n - 1)):
  if s[i] * 2 >= a[i + 1]:
    res += 1
  else:
    break

print(res)

Submission status: Accepted

Solution code:
N = int(input())

size_list = [int(i) for i in input().split()]
size_list.sort(reverse=True)

cnt = 1
compare = sum(size_list)

for i in range(N):
    compare -= size_list[i]
    if compare * 2 < size_list[i]:
        break
    cnt += 1

print(cnt)