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:
import numpy as np
N = int(input())
x = list(map(int,input().split()))
x.sort()
x_cm = np.cumsum(x)[::-1]
x = x[::-1]
count = 1
for i in range(N-1):
    if x[i]<=x_cm[i+1]*2:
        count += 1
    else:
        break

print(count)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    A = LI()
    A.sort()

    sm = 0
    j = -1
    for i, a in enumerate(A[:-1]):
        sm += a
        # print(sm, 2 * sm, A[i+1])
        if 2 * sm >= A[i+1]:
            pass
        else:
            j = i
    # print(j)
    print(N - (j + 1))

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from itertools import accumulate

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    CUSUM = tuple(accumulate(A))

    sub = 0
    for i in range(N-1):
        if CUSUM[i]*2 < A[i+1]:
            sub = i+1
    print(N-sub)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

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

print(cnt)

Submission status: Accepted

Solution code:
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse=True)
    s = [0]
    for i in range(n-1):
        s.append(s[-1]+a[~i])
    s.reverse()
    for i in range(n):
        if a[i] >  s[i]*2:
            break
    print(i+1)  

    
if __name__ == '__main__':
    main()

Submission status: Accepted

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
idx = 1
for i in range(len(res)):
    num = res[i]
    if(idx <= 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: 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] + a[i]
cnt = 1
for i in reversed(range(1,N)):
    if(a[i] > a[i-1] * 3): 
        break
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()
    A.sort()

    # Aがあるサイズ以上であればその色にできる
    # 自分より小さいやつを全部吸収した後で、自分より大きいやつを全部吸収できるか
    A_cum = [0] * (N + 1)
    for i in range(N):
        A_cum[i+1] = A_cum[i] + A[i]

    l = [A_cum[i] * 2 >= A[i] for i in range(1, N)]
    l.reverse()
    if False in l:
        print(l.index(False) + 1)
    else:
        print(N)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

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()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

"""
6
40 1 30 2 7 20
"""

N = getN()
A = getList()
A.sort()
imos = copy.deepcopy(A)
for i in range(N - 1):
    imos[i + 1] += imos[i]

# 自分より小さい怪物を全て飲み込んだときに一つ上の怪物を飲み込めるか
streak = [0] * N
streak[-1] = 1
for i in range(N - 1):
    if imos[i] * 2 >= A[i + 1]:
        streak[i] = 1

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

Submission status: Accepted

Solution code:

def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    a.sort()
    
    sm = 0
    ans = 0
    for i in range(n-1):
        sm += a[i]
        if sm * 2 >= a[i+1]:
            ans += 1
        else:
            ans = 0
    print(ans+ 1)

solve()

"""
5 6
4 7 9 3 4
"""

Submission status: Accepted

Solution code:
from itertools import accumulate

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

a.sort()

b = list(accumulate(a))

point = 0

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

print(point+1)

Submission status: Accepted

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()
a.sort()

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

ans+=1
print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = [0]+list(mapint())
As.sort()
from itertools import accumulate
cAs = list(accumulate(As))
cAs.sort(reverse=True)
As.sort(reverse=True)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()
a.sort()

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

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

print(ans)

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
a.sort()
v=t=0
for i in range(1,n):v+=a[i-1];t=[t,i][2*v<a[i]]
print(n-t)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import*
n,*a=map(int,open(t:=0).read().split())
a.sort()
*b,=accumulate(a)
for i in range(1,n):
 if 2*b[i-1]<a[i]:t=i
print(n-t)

Submission status: Accepted

Solution code:
from itertools import*
n, *a = map(int, open(t := 0).read().split())
a.sort()
*b, = accumulate(a)
for i in range(1, n):
  if 2 * b[i - 1] < a[i]:t = i
print(n - t)

Submission status: Accepted

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

Submission status: Accepted

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

S = [0]*(N+1)
for i in range(1, N+1):
    S[i] = S[i-1] + A[i-1]

for i in range(N)[::-1]:
    if S[i]*2 < A[i]:
        print(N-i)
        exit()

Submission status: Accepted

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

Submission status: Accepted

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

s = sorted(A)

ac = 0
startI = 0
for i, a in enumerate(s):
    if i == len(s) - 1:
        print(len(s) - startI)
        exit()

    ac += a

    if ac * 2 < s[i+1]:
        startI = i+1

Submission status: Accepted

Solution code:
def solve(n, a):
    a = sorted(a)
    total = 0
    optimal = 0
    for i in range(n-1):
        total += a[i]
        if total * 2 < a[i+1]:
            optimal = i+1
    return n - optimal

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

Submission status: Accepted

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

import itertools
Ruisekiwa = list(itertools.accumulate(A))

count = 1

Dekiru = [0]*N
Dekiru[N-1] = 1

for i in range (1, N):
	if 2*Ruisekiwa[N-i-1] >= A[N-i] and Dekiru[N-i] == 1:
		count+=1
		Dekiru[N-i-1]=1
        
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import bisect
n=int(input())
a=list(map(int,input().split()))
a.sort()
#print(a)
x=bisect.bisect_left(a,a[-1]/2)
#print(x)
ans=n-x#そのままの状態で条件を満たす和
if x==0:
    print(ans)
    exit()
i=x-1
j=x
tmp=a[i]
ref=a[x]
SUM=sum(a[:i+1])
#print(SUM)
for k in range(i,-1,-1):
    if k==i:
        if 2*SUM>=a[k+1]:
            ans+=1
        else:
            break
    else:
        SUM-=a[k+1]
        #print(SUM,k,ans)
        if 2*SUM>=a[k+1]:
            ans+=1
        else:
            break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect

N = int(input())
A = sorted(map(int, input().split()))
M = max(A)
cs = [0] #si=[0,i)の和 [a,b)の和=sb−sa
for i in A:
    cs.append(cs[-1] + i)
A.append(A[-1])
ans = 0
for i in range(N, 0, -1):
    if cs[i] * 2 >= A[i]:
        ans += 1
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
import sys
from itertools import accumulate

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')


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

    R = [0] + list(accumulate(A))
    left = 0
    for i in range(n):
        if R[i] * 2 < A[i]:
            left = i
    print(n - left)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

import numpy as np

A = sorted(A)
B = np.cumsum(A)

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

Submission status: Accepted

Solution code:
import math
import collections
import itertools
import heapq

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

    revs_A = sorted(A, reverse=True)
    double_A = sorted(list(map(lambda x: 2*x, A)))
    cum_double_A = list(itertools.accumulate(double_A))[::-1]
    res = 1
    for i, a in enumerate(cum_double_A[1:]):
        if a >= revs_A[i]:
            res += 1
        else:
            break
    print(res)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = sorted(LIST())

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

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
a = lr()
a.sort()
a1 = [0]
for num in a:
    a1.append(a1[-1]+num)
def sumArea(l,r):
    return a1[r]-a1[l]
ans = 1
for i in range(1,n):
    if a[n-i] > 2*sumArea(0,n-i):
        break
    else:
        ans+=1
print(ans)

Submission status: Accepted

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

A.sort()
stop = N
for i in reversed(range(N-1)):
    if A[i]* 2 < A[i+1]:
        if 2 * sum(A[:i+1]) < A[i+1]:
            stop = i
            break

print(len(A[stop+1:]) if stop != N else N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from bisect import *
n=int(input())
a=sorted(list(map(int,input().split())))
tmp=a[0]
ans=1
aa=1
for i in range(1,n):
    if tmp*2>=a[i]:
        tmp+=a[i]
        ans+=1
    else:
        tmp+=a[i]
        ans=1
print(ans)

Submission status: Accepted

Solution code:
n, *aa = map(int, open(0).read().split())

aa.sort()

count = 1
tmp = aa[0]
for i in range(1,n):
    if 2 * tmp >= aa[i]:
        tmp += aa[i]
        count += 1
    else:
        tmp += aa[i]
        count = 1
#     print(count, tmp)

print(count)

Submission status: Accepted

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

from itertools import accumulate

ans = 1
cumsum = list(reversed(list(accumulate(A))))

for a,cs in zip(reversed(A), cumsum[1:]):
    if a <= 2*cs:
        ans += 1
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from itertools import accumulate
    n = int(readline())
    a = list(map(int, readline().split()))
    a.sort()
    acc = list(accumulate(a))

    ok = n - 1
    ng = -1

    while abs(ng - ok) > 1:
        mid = (ok + ng) // 2
        i = mid
        cur = acc[i]
        while i < n - 1:
            if 2 * cur >= a[i + 1]:
                cur += a[i + 1]
                i += 1
            else:
                break
        if i == n - 1:
            ok = mid
        else:
            ng = mid

    print(n - ok)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    A = sorted(in_nl())

    asum = [0] * (N + 1)
    for i in range(N):
        asum[i + 1] = asum[i] + A[i]

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N = INT()
A = LIST()

A.sort()

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

cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort()
sA = [0]
for i in range(n):
    sA.append(sA[i]+A[i])

A = A[::-1]
sA = sA[::-1]
ans = 1
for i in range(1,n):
    if 2*sA[i]>=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()
temp=[a[0]]
for i in range(n-1): temp.append(temp[i]+a[i+1])
a.sort(reverse=True)
temp.reverse()
flag=1
for i in range(n-1):
    if a[i]>2*a[i+1] and a[i]>2*temp[i+1]:
        flag=0
        print(i+1)
        break
if flag: print(n)

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
a.sort()
def sub(x):
    v = a[x]
    for i,num in enumerate(a):
        if i==x:
            continue
        if v*2>=num:
            v += num
        else:
            ans = False
            break
    else:
        ans = True
    return ans
if sub(0):
    ans = n
elif not sub(n-1):
    ans = 0
else:
    l = 0
    r = n
    while l<r-1:
        m = (l+r)//2
        if sub(m):
            r = m
        else:
            l = m
    ans = n-r
print(ans)

Submission status: Accepted

Solution code:
import copy
n=int(input())
a=list(map(int,input().split()))
a.sort()
c=i=st=0

while i <n-1:
  
  if 2*(a[st]+c) >= a[i+1]:
    c+=a[i+1]
    i+=1
    
  else:
    c=a[st]+c
    st=i+1
    i+=1
    
print(n-st)

Submission status: Accepted

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

a = a[::-1]
b = b[::-1]

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

Submission status: Accepted

Solution code:
from itertools import accumulate

n = int(input())
As = list(map(int, input().split()))
As.sort()
acc = [0] + list(accumulate(As))
# print(As, acc)
"""
それまでの累積和が次のやつを食うかどうか
食えない⇨それ以前はいくら頑張ってもダメ
1 2 7 20 30 40
1 3 10 30 60 100 
"""
for i in range(1,n+1):
    if i == 0:continue
    if As[-i] > acc[-i-1]*2:
        break
print(i)

Submission status: Accepted

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

A.sort()
#print(A)

ans = 0
size = 0
for i in range(n):
    if A[i] <= 2*size:
        ans += 1
    else:
        ans = 1
    size = A[i] + size

print(ans)

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    ret = 1
    cluester_volume = A[0]
    for a in A[1:]:
        if a <= cluester_volume*2:
            ret += 1
        else:
            ret = 1
            
        cluester_volume += a
            
    print(ret)
    
solve()

Submission status: Accepted

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

import numpy as np
cum=list(np.cumsum(a))

cnt=0
for i in range(n-1,-1,-1):
    if i==n-1:
        cnt+=1
        continue

    if 2*cum[i]>=a[i+1]:
        cnt+=1
    else:
        break

print(cnt)

Submission status: Accepted

Solution code:
import numpy as np


n = int(input())
a = np.array(list(map(int, input().split())))
a.sort()
a_cum = a.cumsum()
ng = a_cum[:-1] * 2 < a[1:]
ng = np.logical_or.accumulate(ng[::-1])[::-1]
x = (~ng).sum() + 1
print(x)

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
a=list(map(int,input().split()))
a.sort()
rui=list(accumulate(a))
# print(rui)

cnt=0
now=0
for now in range(n-1):
    if rui[now]*3>=rui[now+1]:
        cnt+=1
    else:
        cnt=0
print(cnt+1)

Submission status: Accepted

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

A = sorted(A)
A = A + [-1]

ans = 0
total = 0
for i in range(N):
    total += A[i]

    if total >= A[i+1]/2:
        ans += 1
    else:
        ans = 0

print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    A = sorted(list(map(int, input().split())))
    B = [A[0], ]
    s = A[0]
    for a in A[1:]:
        s += a
        B.append(s)
    ans = 1
    for i in range(n - 1, 0, -1):
        if B[i - 1] * 2 >= A[i]:
            ans += 1
        else:
            break
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 26 21:20:10 2020

@author: NEC-PCuser
"""

N = (int(input()))

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

A.sort()

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
sm = 0
p = -1
# print(A)
for i in range(N-1):
    sm += A[i]
    if 2*sm < A[i+1]:
        p = i
    # print(sm,2*A[i+1])
# print(p)
print(N-p-1)

Submission status: Accepted

Solution code:
import sys

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))
A.sort()

s = 0
res = 0

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

print(res + 1)