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 sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

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

Submission status: Accepted

Solution code:
import itertools
def main():
    n=int(input())
    a=sorted(map(int,input().split()))
    b=list(itertools.accumulate(a))
    cnt=0
    for i in reversed(range(1, n)):
        if b[i-1]*2 < a[i]:
            return n-i
    return n
            
if __name__ == "__main__":
    print(main())

Submission status: Accepted

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

B = []; b = 0
for i in A:
    b += i
    B.append(b)

c = 1; w = True
while w:
    if 2*B[N-1-c] >= A[N-c]:
        c += 1
        if c == N: break
    else:
        w = False

print(c)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


class Solver():
    def __init__(self, target):
        self.target = target

    def bin_search(self, l, r):
        if l + 1 == r:
            if self.check(l):
                return l - 1
            return l

        c = (l+r) // 2

        is_c_achieve = self.check(c)

        if is_c_achieve:
            return self.bin_search(l, c)
        else:
            return self.bin_search(c, r)

    def check(self, c):
        others = cl.deque(self.target)
        others.remove(self.target[c])
        mine = self.target[c]

        while len(others) > 0:
            minest = others.popleft()
            if mine * 2 >= minest:
                mine += minest
            else:
                return False
        return True


def main():
    N = II()
    target = LI()
    target.sort()
    solver = Solver(target)
    ans = solver.bin_search(0, N - 1)
    print(N - ans - 1)


main()

Submission status: Accepted

Solution code:
n,*A=map(int,open(a:=0).read().split());A=[0]+sorted(A);S=[0]*(n+1)
for i in range(1,n+1):S[i]=S[i-1]+A[i]
for x,y in zip(A[:0:-1],S[-2::-1]):
  a+=1
  if x>y*2:break
print(a)

Submission status: Accepted

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

a = sorted(a)

l = 0
r = n

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

    size = sum(a[:mid+1])
    ptr = mid+1
    ans = True

    while ptr < n:
        if 2*size >= a[ptr]:
            size += a[ptr]
            ptr += 1
        else:
            ans = False
            break

    if ans:
        r = mid
    else:
        l = mid+1

print(n-l)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
dp, S = 0, 0
for i, a in enumerate(A):
    if S*2 < a:
        dp = i
    S += a
print(N-dp)

Submission status: Accepted

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


last_impossible = 0
s = 0
for i,a in enumerate(A):
    if a > 2*s:
        last_impossible = i
    s += a

print(N-last_impossible)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
A=sorted(A)
nums=[]
num=0
ans=1
for a in A:
    num+=a
    nums.append(num)
for n in range(N-2,-1,-1):
    if nums[n]*2>=A[n+1]:
        ans+=1
    else:
        break
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
alst = list(map(int, input().split()))
alst.sort()
pos = 0
total = 0
for i, a in enumerate(alst):
    if a > total * 2:
        pos = i
    total += a
print(n - pos)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    n=I()
    lis=LI()
    lis.sort()
    #print(lis)
    sm=list(accumulate(lis))
    #print(sm)
    count=1
    for i in range(n-1):
        j=n-1-i
        if 2*sm[j-1]>=lis[j]:
            count+=1
        else:
            break
    print(count)
    






if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    N = int(input())
    As = [int(item) for item in input().split()]
    As.sort()
    res = 1
    remain = sum(As)

    for i in range(N-1):
        temp = As[-1 * (i + 1)]
        remain -= temp

        if temp <= remain * 2:
            res += 1
        else:
            break

    print(res)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

for i in range(n-2,-1,-1):
    if a[i+1] > cum[i]*2:
        print(n-i-1)
        exit()
print(n)

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
A = [0] + LI()
A.sort()


def f(n):  # 大きさが小さい方からn番目の生き物の色が、最後に残りうるか
    a = sum(A[i] for i in range(1,n+1))
    for i in range(n+1,N+1):
        if a*2 >= A[i]:
            a += A[i]
        else:
            return False
    return True


left = 0  # ng
right = N  # ok
while left + 1 < right:
    mid = (left + right)//2
    if f(mid):
        right = mid
    else:
        left = mid

print(N-right+1)

Submission status: Accepted

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

asum=[A[0]]
j=1
for i in range(1,N):
    if asum[i-1]*2<A[i]:
        ans-=j
        j=0
    asum.append(asum[i-1]+A[i])
    j+=1
    
print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

A.sort()
# print(A)
ans = 0

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

print(ans + 1)

Submission status: Accepted

Solution code:
from copy import copy
n, *a = map(int, open(0).read().split())
a.sort()
b = copy(a)
for i in range(n - 1):
    b[i + 1] += b[i]

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

Submission status: Accepted

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

main()

Submission status: Accepted

Solution code:
from itertools import accumulate

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

A.sort()

check = list(accumulate(A))

for key in range(N-1, 0, -1):
    if check[key-1] * 2 < check[key] - check[key-1]:
        print(N - key)
        exit()

print(N)

Submission status: Accepted

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

import numpy as np

a=sorted(a)
cum = np.cumsum(a)

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

print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate


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


N = int(input())
A = Li()
A.sort()
Asum = list(accumulate(A))
ans = 0
for i in range(N-1):
    if Asum[i]*2 >= A[i+1]:
        ans += 1
    else:
        ans = 0
print(ans+1)

Submission status: Accepted

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

A.sort()

def check(sz):
    # print("check:", sz)
    skp = False
    cannot_eat = False
    check = sz
    for i in A:
        if skp == False and sz == i:
            skp = True
            continue

        if i > check * 2:
            cannot_eat = True
            break
        else:
            check += i
    # print("result:", cannot_eat)
    return not cannot_eat

ok = N
ng = -1


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

    if check(A[mid]):
        # ok
        ok = mid
    else:
        # ng
        ng = mid
    
    # print(ok, ng)

print(N-ok)

Submission status: Accepted

Solution code:
N = int(input())

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

A.sort()

memo = [0]*N

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

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

Submission status: Accepted

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

Submission status: Accepted

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

A=sorted(A)

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
A = LI()
A.sort()


def f(n):
    a = sum(A[i] for i in range(n+1))
    for i in range(n+1,N):
        if a*2 >= A[i]:
            a += A[i]
        else:
            return False
    return True


left = -1  # ng
right = N-1  # ok
while left + 1 < right:
    mid = (left + right)//2
    if f(mid):
        right = mid
    else:
        left = mid
print(N-right)

Submission status: Accepted

Solution code:
from itertools import accumulate

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

arr.sort()

# 1つ前までの累積和の2倍がその時点の要素の大きさに達しているかどうか
cumsum = list(accumulate(arr))

result = []
for x, y in zip(arr[1:], cumsum[:-1]):
    if x <= y * 2:
        result.append(True)
    else:
        result.append(False)

if all(result):
    ans = n
else:
    ans = result[::-1].index(False) + 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 = list(mapint())
As.sort()
from itertools import accumulate
cumAs = list(accumulate([0]+As))

ans = 0
cum = 0
for i in range(N-1):
    a = As[i]
    cum += a
    if cum*2<As[i+1]:
        ans = 0
    else:
        ans += 1

print(ans+1)

Submission status: Accepted

Solution code:
from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))
A.sort()
accumA = [*accumulate(A)]
check = [0] * (N-1)
for i in range(N-1):
    if A[i+1] <= 2*accumA[i]:
        check[i] = 1
ans = 1
j = N-2
while check[j]:
    ans += 1
    j -= 1
    if j == -1:
        break
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions
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()))

n = inp()
a = inpl()
a.sort()
b = list(itertools.accumulate(a))
for i in range(n-1)[::-1]:
    if b[i]*2 < a[i+1]:
        res = n-i-1
        break
else:
    res = n
print(res)

Submission status: Accepted

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

al.sort()
curr_ans = 1
curr_sum = al[0]
for a in al[1:]:
    if curr_sum*2 >= a:
        curr_ans += 1
        curr_sum += a
    else:
        curr_ans = 1
        curr_sum += a

print(curr_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:
    ans = 1
    now += A[i]
  else:
    ans += 1
    now += A[i]
print(ans)

Submission status: Accepted

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

color_min = 0
creature_size = A[0]

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

ans = N - color_min

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    S = [0] * N  # 累積和
    S[0] = A[0]
    for n in range(1, N):
        S[n] = S[n - 1] + A[n]
    n = N - 2
    while n >= 0:
        if 2 * S[n] < A[n + 1]:  # A_n までの数字で A_(n+1)を吸収できない
            break
        n -= 1
    print(N - 1 - n)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

size = sum(a)
capa = size*2
count = 1

for i,x in enumerate(a[1:]):
    size -= a[i]
    capa = size * 2
    if a[i] <= capa:
        count += 1
    else:
        break

print(count)

Submission status: Accepted

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

A.sort()

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

print(ans+1)

Submission status: Accepted

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

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

A = sorted(A)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import numpy as np

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(input())
    A = np.array(input().split(), np.int64)
    A = np.sort(A)
    Acum = np.cumsum(A)
    ans = 1
    for i in range(N-2,-1,-1):
        if Acum[i]*2 >= A[i+1]:
            ans += 1
        else:
            break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(map(int, input().split()))
sum_A = sum(A)
count = N
for i in range(N - 1, -1, -1):
    sum_A -= A[i]
    if (sum_A) * 2 >= A[i]:
        continue

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

print(count)

Submission status: Accepted

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

ru = [A[0]]
for i in range(1, N):
    ru.append(A[i]+ru[-1])

x = 0
for i in range(N-1, 0, -1):
    if ru[i-1]*2 < A[i]:
        x = i
        break

print(N-x)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
import bisect
import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal

INF = 1 << 50


def run():
    N, *A = map(int, read().split())
    A = sorted(A)
    B = []
    val = 0
    for a in A:
        val += a
        B.append(val)

    left = -1
    right = -1
    for i in range(N-1):
        if B[i] * 3 >= B[i+1]:
            if left == -1:
                left = i
                right = i+1
            else:
                right = i+1
        else:
            left, right = -1, -1
    print(right - left + 1)


if __name__ == "__main__":
    run()

Submission status: Accepted

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

print(n-t)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
a.sort()
acc = [0]*(n+1)
for i in range(1,n):
    acc[i] = acc[i-1]+a[i-1]
#ddprint(a)
#ddprint(acc)
for i in range(n-1,-1,-1):
    if a[i]>2*acc[i]:
        print(n-i)
        exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n,*a=map(int, open(0).read().split())
a.sort()
ans = 0
c  = 0
for i in range(n-1):
    c += a[i]
    if c*2 < a[i+1]:
        ans = 0
    else:
        ans += 1
print(ans + 1)

Submission status: Accepted

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

# In[26]:


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


# In[32]:


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


# In[ ]:

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
*A,=map(int,input().split())
A.sort()
ans=1
S=0
i=0
while i+1<N:
    S+=A[i]
    if 2*S>=A[i+1]:
        ans+=1
    else:
        ans=1
    i+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#==========================================================
def General_Binary_Search(L,R,cond,Mode=True,Integer=True,ep=1/(1<<20)):
    """一般的な二部探索を行う.
    L:解の下限
    R:解の上限
    cond:条件(1変数関数,広義単調減少 or 広義単調減少を満たす)
    Mode:True->広義単調増加,False->広義単調減少
    Integer:解を整数に制限するか?
    ep:Integer=Falseのとき,解の許容する誤差
    """

    if Integer:
        if Mode:
            if not cond(R):
                return R+1
            L-=1
        else:
            if not cond(L):
                return L-1
            R+=1

        while R-L>1:
            C=L+(R-L)//2
            if cond(C)^Mode:
                L=C
            else:
                R=C
        if Mode:
            return R
        else:
            return L
    else:
        C=L+(R-L)/2
        while (R-C)>ep:
            if cond(C)^Mode:
                L=C
            else:
                R=C
            C=L+(R-L)/2
        return C
#==========================================================
def g(x):
    S=A[x]
    for i in range(N):
        if i!=x:
            if A[i]<=2*S:
                S+=A[i]
            else:
                return False
    return True
#==========================================================
N=int(input())
A=list(map(int,input().split()))

A.sort()
print(N-General_Binary_Search(0,N-1,g,True))

Submission status: Accepted

Solution code:
#==========================================================
def General_Binary_Search(L,R,cond,Mode=True,Integer=True,ep=1/(1<<20)):
    """一般的な二部探索を行う.
    L:解の下限
    R:解の上限
    cond:条件(1変数関数,広義単調減少 or 広義単調減少を満たす)
    Mode:True->広義単調増加,False->広義単調減少
    Integer:解を整数に制限するか?
    ep:Integer=Falseのとき,解の許容する誤差
    """

    if Integer:
        if Mode:
            if not cond(R):
                return R+1
            L-=1
        else:
            if not cond(L):
                return L-1
            R+=1

        while R-L>1:
            C=L+(R-L)//2
            if cond(C)^Mode:
                L=C
            else:
                R=C
        if Mode:
            return R
        else:
            return L
    else:
        C=L+(R-L)/2
        while (R-C)>ep:
            if cond(C)^Mode:
                L=C
            else:
                R=C
            C=L+(R-L)/2
        return C
#==========================================================
def g(x):
    S=A[x]
    for i in range(N):
        if i!=x:
            if A[i]<=2*S:
                S+=A[i]
            else:
                return False
    return True
#==========================================================
N=int(input())
A=list(map(int,input().split()))

A.sort()

if not g(N-1):
    print(0)
elif g(0):
    print(N)
else:
    print(N-General_Binary_Search(0,N-1,g,True))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

def judge(x):
    B = [A[i] for i in range(N) if i!=x]
    now = A[x]
    
    for Bi in B:
        if Bi>2*now:
            return False
            
        now += Bi
    
    return True

def binary_search():
    l, r = 0, N-1
    
    while l<=r:
        m = (l+r)//2
        
        if judge(m):
            r = m-1
        else:
            l = m+1
    
    return l
    
N = int(input())
A = list(map(int, input().split()))
A.sort()
print(N-binary_search())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

c_sum = al[0]
cnt = 1
for a in al[1:]:
    if c_sum*2 >= a:
        c_sum += a
        cnt += 1
    else:
        c_sum += a
        cnt = 1

print(cnt)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = lambda:sys.stdin.readline().strip()
    
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()

    #累積和ac_Ai<Ai+1/2の場合を除外した数
    from itertools import accumulate
    acc_A = list(accumulate(A))

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

    print(ans)

    
if __name__=='__main__':
    main()

Submission status: Accepted

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

import sys
input = sys.stdin.buffer.readline

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

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

ptr = 0
for i in range(1, n + 1):
    if cul_sum[i] * 2 < A[i]:
        ptr = i
    elif cul_sum[i] * 2 >= _max:
        print(n - ptr)
        sys.exit()

Submission status: Accepted

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

l = 0
r = n - 1

def hantei(c):
    a1 = a[:c] + a[c+1:]
    tmp = a[c]
    flag = True
    for i in a1:
        if tmp * 2 >= i:
            tmp += i
        else:
            flag = False
            break
    return flag


while r - l > 1:
    c = int((l + r)//2)
    if hantei(c):
        r = c
    else:
        l = c

if hantei(l):
    print(n - l)
else:
    print(n - l - 1)

Submission status: Accepted

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

As.sort()

Ss = [As[0]]

for i in range(1,N):
  Ss.append(Ss[-1] + As[i])
  
cnt = 0
for i in range(N-1):
  if 2*Ss[i] < As[i+1]:
    cnt = i+1
    
print(N-cnt)

Submission status: Accepted

Solution code:
# coding: utf-8
import bisect
import math
#N, c, k = map(int,input().split())
N = int(input())
#T = []
A = list(map(int,input().split()))
A.sort()
A_ = sorted(A)
ans = 0
for i in range(N-1):
    A_[i+1] += A_[i]
#print(A)
#print(A_)
t=0
for i in range(N-1):
    #print(ans)
    if A_[i]*2 >= A[i+1]:
        ans += 1
    else:
        ans = 0
ans += 1
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
import bisect
import math
#N, c, k = map(int,input().split())
N = int(input())
#T = []
A = list(map(int,input().split()))
A.sort()
A_ = sorted(A)
ans = 0
for i in range(N-1):
    A_[i+1] += A_[i]
#print(A)
#print(A_)
for i in range(N-1):
    #print(ans)
    if A_[i]*2 >= A[i+1]:
        ans += 1
    else:
        ans = 0
ans += 1
print(ans)

Submission status: Accepted

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

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

    S = A[0]
    ans = 1
    for a in A[1:]:
        if S * 2 < a:
            ans = 0
        S += a
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

A.sort()
tmp = A[0]
ans = 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=int(input())
a=[0]+sorted(list(map(int,input().split())))
for i in range(n):
  if 2*a[i]<a[i+1]:flag=0
  else:flag=1
  a[i+1]+=a[i]
  a[i]*=flag
ans=0
for i in a[::-1]:
  if i:ans+=1
  else:break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)