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())
A = np.array(list(map(int, input().split())))
A.sort()
cumsum = A.cumsum()
# sortした後にcumsumを２倍しても一つ隣のAより大きくなっていないものは最後に残れない
# 後ろから調べていって途切れたらそこから左みんなダメ
# print('A', A)
# print('cumsum', cumsum)

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

Submission status: Accepted

Solution code:
import heapq

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

A.sort(reverse=True)

def condition(num):
    test=A[:num]+A[num+1:]
    s=A[num]
    heapq.heapify(test)
    while test:
        x=heapq.heappop(test)
        if 2*s>=x:
            s+=x
        else:
            return False
    return True

start=0
end=N-1
while end-start>1:
    t=(end+start)//2
    if condition(t):
        start=t
    else:
        end=t

if condition(end):
    print(end+1)
elif condition(start):
    print(start+1)
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
A.sort()
S=[]
s=0
for i in range(n):
    s+=A[i]
    S.append(s)
ans=1
for i in reversed(range(n-1)):
    if S[i]*2>=A[i+1]:
        ans+=1
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import itertools

n = int(readline())
a = sorted(tuple(map(int, readline().split())))
cnt = 1
cumsum = list(itertools.accumulate(a))
for i in range(1, n):
    if cumsum[i - 1] * 2 < a[i]:
        n -= cnt
        cnt = 0
    cnt += 1
print(n)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
A.sort()
B = np.cumsum(A)

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

print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    def f(x):
        tmp = a[x]
        for i in range(n):
            if i != x:
                if tmp * 2 >= a[i]:
                    tmp += a[i]
                else:
                    return False
        return True
    n = II()
    a = LI()
    a.sort()
    ok = n - 1
    ng = -1
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if f(mid):
            ok = mid
        else:
            ng = mid
    print(n - ok)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_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

N = INT()
A = LIST()
A.sort()
A_acc = list(accumulate(A))[::-1]
A = A[::-1]
ans = 1
for i in range(1, N):
	if A_acc[i]*2 >= A[i-1]:
		ans += 1
	else:
		break
print(ans)

Submission status: Accepted

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

ai.sort()

tmp = ai[0]
num = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


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


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
# sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = True
show_flg = False


def main():
    N = I()
    A = LI()
    A = sorted(A)
    acc = list(accumulate(A))
    mag = []

    for i in range(N-1):
        mag.append(A[i+1] / acc[i])

    # print(A)
    # print(acc)
    # print(mag)

    ans = 0
    for i in range(len(mag)):
        if mag[i] > 2.0:
            ans = 0
        else:
            ans += 1

    print(ans + 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
l=sorted(list(map(int,input().split())))
ans,s=1,0
for u in l:
  if 2*s>=u:ans+=1
  else:ans=1
  s+=u
print(ans)

Submission status: Accepted

Solution code:
sel=4
#ICC-D3-J
if sel==1: print('Judgement')

#ARC030-A
if sel==2:
    N=int(input())
    K=int(input())
    if 2*K-1<N:
        print('YES')
    else:
        print('NO')

#AGC004-A
if sel==3:
    A,B,C=map(int,input().split())
    ans=10**19
    whole=A*B*C
    for a in range(A//2,A//2+2):
        ans=min(ans,abs(whole-a*B*C*2))
    for b in range(B//2,B//2+2):
        ans=min(ans,abs(whole-A*b*C*2))
    for c in range(C//2,C//2+2):
        ans=min(ans,abs(whole-A*B*c*2))
    print(ans)

#AGC011-B
if sel==4:
    import bisect

    #O(N): 長さNの配列に対する累積和(+演算)
    def CS1D(lis): #listを渡す
        ret=[lis[0]]
        for i in range(1,len(lis)):
            ret.append(ret[i-1]+lis[i])
        return ret

    N=int(input())
    A=[int(i) for i in input().split()]
    A.sort()
    CS=CS1D(A)
    ans=0
    # print(A)
    # print(CS)
    # 各Aiに対して、x<=2*Aiを満たすAの最大の元Ajをとって,Ajについても同様にする。
    # こうして、変らなくなるか最後まで行ったら終わり。
    for i in range(N):
        # print('!',i)
        prev=-1
        size=CS[i]
        k=i
        while prev!=k:
            prev=k
            # print(size)
            k=bisect.bisect(A,2*size)-1 #ここまで食べれる
            # print(bisect.bisect(A,2*size))
            size=CS[k]
            if k==N-1:
                ans+=1
                break
    print(ans)

Submission status: Accepted

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

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

print(n-t)

Submission status: Accepted

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
    if 2*prev < x:
        cnt = 1
    else:
        cnt += 1
    prev += x

print(cnt)

Submission status: Accepted

Solution code:
from itertools import accumulate
from bisect import bisect_left as bl
def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()
    ans = N
    tmp = 0
    B = list(accumulate(A))
    for i,b in enumerate(B):
        k = bl(A,b*2)
        if k == N:continue
        if A[k-1] == A[i] and A[k] > 2*b:
            tmp = i+1
    ans -= tmp
    
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from itertools import accumulate


def main():
    creatures = int(input())
    size = [int(x) for x in input().split()]
    size.sort()
    accumulate_size = list(accumulate(size))
    survivable = 0
    for i in range(creatures - 1):
        if 2 * accumulate_size[i] < size[i + 1]:
            survivable = i + 1
    print(creatures - survivable)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
S = [0] * N
total = 0
for i in range(N):
    total += A[i]
    S[i] = total
S = [0] + S
for i in range(1, N + 1):
    if A[-i] > 2 * S[-i - 1]:
        print(i)
        break

Submission status: Accepted

Solution code:
N = list(map(int,input().split()))
A = [(a,idx+1) for idx,a in enumerate(list(map(int,input().split())))]
A = sorted(A)

color_set = set()
prev_sum = 0
prev_num = 0
for a,color in A:
  if prev_num == a or prev_sum*2 >=a :
    color_set |= {color}
  else:
    color_set = {color}
  prev_sum += a
  prev_num = a
  
print(len(color_set))

Submission status: Accepted

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
    if tmp < A[i+1]:
        ind = i

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

Submission status: Accepted

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
    if tmp < A[i+1]:
        ind = i

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

Submission status: Accepted

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

acc = 0
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate

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

a.sort()

acc = list(accumulate(a))

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate

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

cnt = [1] * N
for i in range(N-1):
    # Acum[i]がA[i+1]を吸収できるか
    if A[i+1] <= Acum[i] * 2:
        cnt[i+1] += cnt[i]

print(cnt[-1])

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = sorted(inpl())
b = [0]
for i in a:
    b.append(b[-1]+i)
res = 0
for i in reversed(range(n)):
    if i == n-1: 
        res += 1
        continue
    if (a[i] + b[i])*2 < a[i+1]:
        break
    res += 1
print(res)

Submission status: Accepted

Solution code:
from bisect import bisect_right
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    b = [v for v in a]
    for i in range(1, n):
        b[i] += b[i-1]
    ans = 0
    for i in range(n):
        target = b[i]
        index = bisect_right(a, 2*target)
        while index < n:
            target = b[index-1]
            j = index-1
            index = bisect_right(a, 2*target)
            if j+1 == index:
                break
        if index == n:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

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(1,n):
  b[i]=b[i-1]+a[i]
p=1
for i in range(n-1)[::-1]:
  if b[i]*2>=a[i+1]:
    p+=1
  else:
    break
print(p)

Submission status: Accepted

Solution code:
n, *a = map(int, open(0).read().split())
a = [0] + sorted(a) + [1e9+1]

l, r = 0, n+2
while r-l>1:
        mid = (l+r)//2
        m = a[mid]
        for i in range(n+1):
                if i==mid: continue
                if a[i]<=m*2: m += a[i]
                else: break
        else:
                r = mid
                continue
        l = mid
print(n-l)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = np.array(input().split(), dtype=int)
A.sort()

B = np.cumsum(A)

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

ans += 1
print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    A.sort()
    cur = 0
    ans = 0
    for i in range(N):
        cur += A[i]
        ans += 1
        if i == N-1:
            break
        if A[i+1] <= cur*2:
            continue
        else:
            ans = 0
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8

n = int(input().rstrip())

monsters = list(reversed(sorted(map(int, input().rstrip().split(" ")))))

cnt = [0 for i in range(n)]
cnt[n - 1] = monsters[n - 1]
for i in reversed(range(n - 1)):
    cnt[i] = cnt[i + 1] + monsters[i]

dic = {}


def can_alife(idx: int):
    if idx == 0:
        return True
    if idx in dic:
        return dic[idx]

    ret = False
    if monsters[idx - 1] <= cnt[idx] * 2:
        ret = can_alife(idx - 1)
    dic[idx] = ret
    return ret


ans = len([i for i in range(n) if can_alife(i)])
print(ans)

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter
from itertools import accumulate
def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    C = list(accumulate(A))
    dp = [0] * N
    for i in range(N-1):
        if C[i] * 2 >= A[i+1]:
            dp[i+1] = dp[i] + 1
    print(dp[N-1]+1)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

from itertools import accumulate

Acum = list(accumulate(A))

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

print(cnt[-1])

Submission status: Accepted

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
A.sort()
imos=[a for a in A]
for i in range(N-1):
    imos[i+1]+=imos[i]
#print(A)
#print(imos)
for i in range(N-2,-1,-1):
    if 2*imos[i]<A[i+1]:
        print(N-1-i)
        break
else:
    print(N)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
a.sort()
cs = [0] * (N + 1)
for i in range(N): cs[i + 1] = cs[i] + a[i]
#print(cs, a)
res = 0
for i in range(1, N):
  if cs[i] * 2 >= a[i]: res += 1
  else: res = 0
print(res + 1)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=sorted(A)
import numpy
C=numpy.cumsum(B)
cnt=1
for i in range(N-1):
  if C[-2-i]*2>=B[-1-i]:
    cnt+=1
  else:
    print(cnt)
    exit()
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# AGC 011 B - Colorful Creatures
from itertools import accumulate
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=[0]+a
b=list(accumulate(a))
# print('a:',a)
# print('b:',b)
cnt=0
for i in range(n-1):
    if a[i+1]>2*b[i]:
        cnt=i+1
print(n-cnt)

Submission status: Accepted

Solution code:
N,*A=map(int, open(0).read().split())
A=sorted(A)
ans=1
acc=0
for a in A:
    if a>acc*2:
        ans=1
    else:
        ans+=1
    acc+=a
print(ans)

Submission status: Accepted

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

A = sorted(A)

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

Submission status: Accepted

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

s = sum(a)
for i, v in enumerate(a):
    s -= v
    if s*2 < v:
        print(i+1)
        break

Submission status: Accepted

Solution code:
def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def main():
    N = int(input())
    A = read_list()
    A.sort()
    s = 0
    res = 0
    for a in A:
        if s != 0 and s * 2 < a:
            res = 0
        s += a
        res += 1

    print(res)

        
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import bisect

N = int(input())
creatures = list(map(int, input().split()))

creatures.sort()
cumsum = [0]
tmp = 0
for c in creatures:
    tmp += c
    cumsum.append(tmp)

count = 0
for i,c in enumerate(creatures):
    index_new = 0
    index_old = i 
    t = cumsum[i+1]
    #print(f'{i=}')
    #print(f'{t=}')
    while True:
        index_new = bisect.bisect_right(creatures,t*2)
        if N == index_new:
            #print(f'{i=}')
            count += 1
            break
        if index_old+1 < index_new:
            t = cumsum[index_new]
            #print(f'{i=} {t=}')
            index_old = index_new-1
        else:
            break

print(count)

Submission status: Accepted

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

ans = n
cnt = A[0]

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

count = 0
s = a[0]
for i in a[1:]:
    if s * 2 >= i:
        count += 1
    else:
        count = 0
    s += i
else:
    count += 1
    
print(count)

Submission status: Accepted

Solution code:
from itertools import accumulate
N = int(input())
A = sorted(list(map(int,input().split())))
aa = list(accumulate(A))
aa.reverse()
ans = 1
for i in range(N-1):
    if 3*aa[i+1] >= aa[i]:
        ans += 1
    else:
        break
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

ok=n-1
ng=-1

while abs(ok-ng)>1:
 mid=(ok+ng)//2

 inx=mid
 bool=True
 sum_mid=sum(a[:mid+1])

 while bool and inx!=n-2:
  if sum_mid*2>=a[inx+1]:
   sum_mid+=a[inx+1]
   inx+=1
  else:
   bool=False

 if bool:
  ok=mid
 else:
  ng=mid

print(n-ok)

Submission status: Accepted

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

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

cnt=1
for i in reversed(range(1,n)):
    if A[i]<=A[i-1]*3:
        cnt +=1
    else:break

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

a.sort()
t = 0
s = 0
for k, v in enumerate(a):
   s += v
   if k+1 < n and s*2 < a[k+1]:
       t = k+1

print(n-t)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
from itertools import accumulate
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
li.sort()
lin = list(accumulate(li))
point = 1
for i in range(n-1):
    if lin[i]*2 >= li[i+1]:
        point += 1
    else:
        point = 1
print(point)

Submission status: Accepted

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

A.sort()

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

Submission status: Accepted

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

a.sort()


ans = 0
cnt = 0

for i in range(0,N):
    if a[i] <= cnt*2:
        ans += 1
        cnt += a[i]

    else:
        ans = 0
        cnt += a[i]
ans += 1

print(ans)

Submission status: Accepted

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

res = np.cumsum(lst).tolist()
cnt = 0
for i in range(n-1):
    x = res[i]
    if lst[i+1] <= x*2:
        cnt += 1
    else:
        cnt = 0
print(cnt+1)

Submission status: Accepted

Solution code:
def cumulative_sum(l):
    cumu = [0]
    s = 0
    for num in l:
        s += num
        cumu.append(s)
    return cumu

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

A.sort()

C = cumulative_sum(A)

AM = [C[i+1] for i in range(N)]

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

Submission status: Accepted

Solution code:
def cumulative_sum(l):
    cumu = [0]
    s = 0
    for num in l:
        s += num
        cumu.append(s)
    return cumu

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

A.sort()

C = cumulative_sum(A)

AM = [C[i+1] for i in range(N)]

k = 1
for i in range(N):
    AM[i] = max(AM[i],AM[max(0,i-1)])
    for j in range(max(k,i+1),N):
        if AM[i]*2 >= A[j]:
            AM[i] += A[j]
            k = j+1
        else:
            break

S = sum(A)
ans = 0
for i in range(N):
    if AM[i] == S:
        ans += 1
print(ans)

Submission status: Accepted

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



for i in range(n-1,0,-1):
    if lst1[i]-lst1[i-1] > lst1[i-1]*2:
        print(n-i)
        exit()

print(n)

Submission status: Accepted

Solution code:
from itertools import accumulate
n = int(input())
a = list(map(int,input().split()))
a.sort()
acc = list(accumulate(a))
ans = 1
for i in range(n-2,-1,-1):
  if acc[i]*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()
cnt=1
cum=0
for i in range(n-1):
    cum+=A[i]
    if A[i+1]-2*cum<=0:
        cnt+=1
    else:
        cnt=1
print(cnt)

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

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

for i in range(n):
    ans += 1
    if csize*2 < a[i]:
        ans = 1
    csize += a[i]

print(ans)

Submission status: Accepted

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

cnt = 1
for i in reversed(range(1, N)):
    if 2 * (rui[i]) >= a[i]:
        cnt += 1
    else:
        break

print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())
A=sorted(list(map(int,input().split())))
# そこまでの累計(の2倍)より大きければ、そこまでに現れた数字はすべてNG

sums=0
least=0
for i in range(N):
  if A[i]>sums*2:
    least=i
  sums+=A[i]
print(N-least)

Submission status: Accepted

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

A.sort()
sum_A = [0]

for a in A:
    sum_A.append(sum_A[-1] + a)

sum_A.sort(reverse=True)
A.sort(reverse=True)

ans = 1
for i, s in enumerate(sum_A):
    if i == 0:
        continue
    if A[i-1] <= s * 2:
        ans += 1
    else:
        break

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
lis = list(map(int,input().split()))
lis.sort()
li = [0]
for num in lis:
    li.append(li[-1]+num)
def slime(x):
    for i in range(x,n):
        if li[i] * 2 < lis[i]:
            return False
    return True

low = 0
high = n
while high > low+1:
    mid = (high + low) // 2
    if slime(mid):
        high = mid
    else:
        low = mid
print(n-low)

Submission status: Accepted

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

N = int(input().split()[0])
a_list = list(map(int, input().split()))
a_list = list(sorted(a_list))

win_c = 0
total_size = sum(a_list)
max_size_list = []

lose_flag = False
now_size = 0
winner = -1
# 自分より左側のモンスターは確実に吸収できるので
# 自分と自分より左側のモンスターのサイズの総和で右隣のモンスターを吸収できるか考える
#

for i, a in enumerate(a_list):
    if i == N - 1:
        # 最後は確実に勝つ
        if winner == -1:
            winner = i
        break

    now_size += a
    if now_size * 2 >= a_list[i + 1]:
        # 勝てる
        if winner == -1:
            winner = i
    else:
        winner = -1
c = N - winner

ans = c
print(ans)

Submission status: Accepted

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

A.sort()
ans=0
tmp=0
for i in range(0,N):
    if tmp*2<A[i]:
        ans=0
    tmp+=A[i]
    ans+=1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

b = list(accumulate(a))

ans = N
for i in range(N-1)[::-1]:
    if 2 * b[i] < a[i+1]:
        ans -= i+1
        break
        
print(ans)

Submission status: Accepted

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

def hoge(num):
    value=sum(A[:num+1])
    for a in A[num+1:]:
        if value*2>=a:
            value+=a
        else:
            return (0)
    return(1)

if hoge(0):
    print(N)
    exit()

st=0
end=N-1
while end-st>1:

    num=(end+st)//2
    #print(num)
    if not hoge(num):
        st=num
    else:
        end=num

print(N-st -1)

Submission status: Accepted

Solution code:
N = int(input())
A = sorted([int(a) for a in input().split()])[::-1]
s = sum(A)
ans = 1
for a in A:
    s -= a
    if a <= s * 2: ans += 1
    else: break
print(ans)