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

Solution in C# (.NET Core 3.1.201) (judge verdict: Accepted)

using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System;

class Program
{
    #region Reader
    static string ReadStr => Console.ReadLine();
    static string[] ReadStrs => Console.ReadLine().Split(' ');
    static int ReadInt => Convert.ToInt32(Console.ReadLine().Trim());
    static int[] ReadInts => Console.ReadLine().Trim().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
    static long ReadLong => Convert.ToInt64(Console.ReadLine().Trim());
    static long[] ReadLongs => Console.ReadLine().Trim().Split(' ').Select(s => Convert.ToInt64(s)).ToArray();
    static List<int[]> ReadPairs(int N)
    {
        List<int[]> ans = new List<int[]>();
        for (int i = 0; i < N; i++) { ans.Add(ReadInts); }
        return ans;
    }
    static List<long[]> ReadPairsLong(int N)
    {
        List<long[]> ans = new List<long[]>();
        for (int i = 0; i < N; i++) { ans.Add(ReadLongs); }
        return ans;
    }
    #endregion
    #region Method
    const int mod = 1000000007;
    public static int Mod(int a, int mod) { return a % mod >= 0 ? a % mod : a % mod + mod; }
    public static long Mod(long a, long mod = mod) { return a % mod >= 0 ? a % mod : a % mod + mod; }
    bool eq<T, U>() => typeof(T).Equals(typeof(U));
    T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
    T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                       : eq<T, long>() ? ct<T, long>(long.Parse(s))
                       : eq<T, double>() ? ct<T, double>(double.Parse(s))
                       : eq<T, char>() ? ct<T, char>(s[0])
                                         : ct<T, string>(s);
    void Multi<T>(out T a) => a = cv<T>(ReadStr);
    void Multi<T, U>(out (T,U) ans)
    {
        var ar = ReadStrs;
        ans =(cv<T>(ar[0]), cv<U>(ar[1]));
    }
    void Multi<T, U, V>(out (T,U,V) ans)
    {
        var ar = ReadStrs; 
        ans =(cv<T>(ar[0]), cv<U>(ar[1]),cv<V>(ar[2]));
    }
    void Multi<T,U>(out T a,out U b)
    {
        var ar = ReadStrs; 
        a = cv<T>(ar[0]);  b = cv<U>(ar[1]);
    }
    void Multi<T, U, V>(out T a,out U b,out V c)
    {
        var ar = ReadStrs;
        a = cv<T>(ar[0]);  b = cv<U>(ar[1]);  c = cv<V>(ar[2]);
    }
    #endregion


    /// <summary>
    /// とりうる最大値に1を足すこと
    /// </summary>
    /// <param name="minLimit"></param>
    /// <param name="maxLimitPlus1"></param>
    /// <param name="judge"></param>
    /// <returns></returns>
    static long[] BinarySearch(long minLimit, long maxLimitPlus1, Func<long, bool> judge)
    {
        long max = maxLimitPlus1;
        long min = minLimit;
        long mid = (min + max) / 2;

        while (max - min > 1)
        {
            if (judge(mid))
            {
                min = mid;
                mid = (mid + max) / 2;
            }
            else
            {
                max = mid;
                mid = (mid + min) / 2;
            }
        }

        if (max == maxLimitPlus1) return new long[2] { mid, mid + 1 };
        else if (min == minLimit - 1) return new long[2] { -1, 0 };
        else
        {
            return judge(mid) != judge(mid + 1) ? new long[2] { mid, mid + 1 }
            : new long[2] { mid - 1, mid };
        }
    }

    static int[] BinarySearch(IEnumerable<int> numbers, Func<int, bool> judge)
    {
        int max = numbers.Count();
        int min = -1;
        int mid = (min + max) / 2;

        while (max - min > 1)
        {
            if (judge(numbers.ElementAt(mid)))
            {
                min = mid;
                mid = (mid + max) / 2;
            }
            else
            {
                max = mid;
                mid = (mid + min) / 2;
            }
        }

        if (max == numbers.Count()) return new int[2] { mid, mid + 1 };
        else if (min == -1) return new int[2] { -1, 0 };
        else
        {
            return judge(numbers.ElementAt(mid)) != judge(numbers.ElementAt(mid + 1)) ? new int[2] { mid, mid + 1 }
            : new int[2] { mid - 1, mid };
        }
    }

    #region SegmentTree_Lazy

    /// <summary>
    /// 行う演算は結合法則を満たす必要あり
    /// </summary>
    public class SegmentTree<T> where T : IComparable
    {
        /// <summary>
        /// 完全二分木
        /// </summary>
        protected T[] Data { get; }

        /// <summary>
        /// 完全二分木に含まれる葉の数
        /// </summary>
        protected int LeavesCount { get; }

        /// <summary>
        /// 数列(問題などで与えられる)の要素数
        /// </summary>
        public int Count { get; }

        /// <summary>
        /// 葉のうち使われなかったもの、そしてQueryで引数として取得した範囲がDataのインデックスの外である場合に使う
        /// </summary>
        public T Default { get; }

        protected T[] lazy;


        public SegmentTree(T[] data, T def)
        {

            //初期値の設定
            Count = data.Length;
            Default = def;
            LeavesCount = (int)Pow(2, Ceiling(Log(data.Length, 2)));
            Data = new T[LeavesCount * 2 - 1];
            lazy = new T[LeavesCount * 2 - 1];
            //

            //完全二分木の全要素を初期化
            for (int i = 0; i < Data.Length; i++)
            {
                Data[i] = def;
                lazy[i] = def;
            }

            //dataを用いて必要な要素をすべて埋める
            for (int i = 0; i < data.Length; i++)
            {
                this[i] = data[i];
            }

           // WriteLine("初期化完了");
        }

        public T this[int index]
        {
            get
            {
                return Query(index, index + 1);
            }
            set
            {
                Update(index, index + 1, value);
            }
        }

        public void Update(int a, int b, T newValue)
        {
            Update_sub(a, b, 0, LeavesCount, 0, newValue);
        }

        protected virtual void Update_sub(int a, int b, int l, int r, int current, T newValue)
        {
            Eval(current);
            if (a <= l && r <= b)
            {
                lazy[current] = newValue;
                Eval(current);
            }
            else if (a < r && l < b)
            {
                var children = GetChildIndexes(current);

                Update_sub(a, b, l, (l + r) / 2, children.l, newValue);
                Update_sub(a, b, (l + r) / 2, r, children.r, newValue);
                Data[current] = Select(Data[children.l], Data[children.r]);
            }
        }


        /// <summary>
        /// 唯一の親のインデックスを返す
        /// </summary>
        /// <param name="childIndex"></param>
        /// <returns></returns>
        private int GetParentIndex(int childIndex)
        {
            return (childIndex - 1) / 2;
        }

        /// <summary>
        /// 二つの子のインデックスを返す
        /// </summary>
        /// <param name="parentIndex"></param>
        /// <returns>小さいほうはl、大きいほうはr</returns>
        protected (int l, int r) GetChildIndexes(int parentIndex)
        {
            return (2 * parentIndex + 1, 2 * parentIndex + 2);
        }

        /// <summary>
        /// 親の値を二つの子から決定する
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        private T DecideNewElementFromTwoChildren(int index)
        {
            var children = GetChildIndexes(index);

            return Select(Data[children.l], Data[children.r]);
        }



        /// <summary>
        /// [a,b)の範囲で回答を探す
        /// </summary>
        /// <param name="a"></param>
        /// <param name="halfOpen_b"></param>
        /// <returns></returns>
        public T Query(int a, int halfOpen_b)
        {
            return _Query(a, halfOpen_b, 0, LeavesCount, 0);
        }

        private T _Query(int a, int b, int l, int r, int current)
        {
            Eval(current);

            //Φ
            if (r <= a || b <= l)
            {
                return Default;
            }
            //部分集合
            else if (a <= l && r <= b)
            {
                return Data[current];
            }
            //一部
            else
            {

                //(1) 範囲[l,r)を分割し、子lの回答と子rの回答を取得
                //(2) 二つの回答を比べて、適切(Selectメソッド)な方を返す


                //(1)
                var children = GetChildIndexes(current);
                T t1 = _Query(a, b, l, (l + r) / 2, children.l);
                T t2 = _Query(a, b, (l + r) / 2, r, children.r);

                //(2)
                return Select(t1, t2);
            }

        }

        /// <summary>
        /// 配列のk番と、その葉をlazyの値に更新
        /// (もしlazyがDefaultなら何もしない)
        /// </summary>
        /// <param name="k"></param>
        public virtual void Eval(int k)
        {
            //kがDefaultの時は、伝搬も自身の更新もしない
            if (lazy[k].Equals(Default))
            {
                return;
            }


            //kが葉でないなら伝搬
            if (k < LeavesCount - 1)
            {
                var children = GetChildIndexes(k);

                lazy[children.l] = lazy[k];
                lazy[children.r] = lazy[k];
            }

            //自信を更新
            Data[k] = lazy[k];


            lazy[k] = Default;
        }





        /// <summary>
        /// カスタマイズするところ。二つの子の値から、親の値を決定する方法を定める。
        /// </summary>
        /// <param name="t1">子の値1</param>
        /// <param name="t2">子の値2</param>
        /// <returns></returns>
        protected T Select(T t1, T t2)
        {
            return t1.CompareTo(t2) < 0 ? t1 : t2;
        }

    }

    /// <summary>
    /// 区間足し算
    /// </summary>
    public class SegmentTreeLong : SegmentTree<long>
    {
        public SegmentTreeLong(long[] data, long def) : base(data, def)
        {
        }

        protected override void Update_sub(int a, int b, int l, int r, int current, long newValue)
        {
            Eval(current);
            if (a <= l && r <= b)
            {
                if (lazy[current] == Default)
                {
                    lazy[current] = newValue;
                }
                else
                {
                    lazy[current] += newValue;
                }
                Eval(current);
            }
            else if (a < r && l < b)
            {
                var children = GetChildIndexes(current);

                Update_sub(a, b, l, (l + r) / 2, children.l, newValue);
                Update_sub(a, b, (l + r) / 2, r, children.r, newValue);
                Data[current] = Select(Data[children.l], Data[children.r]);
            }
        }

        /// <summary>
        /// 配列のk番と、その葉をlazyの値に更新
        /// (もしlazyがDefaultなら何もしない)
        /// </summary>
        /// <param name="k"></param>
        public override void Eval(int k)
        {
            //kがDefaultの時は、伝搬も自身の更新もしない
            if (lazy[k] == Default)
            {
                return;
            }


            //kが葉でないなら伝搬
            if (k < LeavesCount - 1)
            {
                var children = GetChildIndexes(k);

                if (lazy[children.l] == Default)
                {
                    lazy[children.l] = lazy[k];
                }
                else
                {
                    lazy[children.l] += lazy[k];
                }

                if (lazy[children.r] == Default)
                {
                    lazy[children.r] = lazy[k];
                }
                else
                {
                    lazy[children.r] += lazy[k];
                }

            }

            //自信を更新
            if (Data[k] == Default)
            {
                Data[k] = lazy[k];
            }
            else
            {
                Data[k] += lazy[k];
            }



            lazy[k] = Default;
        }
    }

    #endregion


    static void Main()
    {
        long N = ReadLong;
        long[] As = ReadLongs;

        Array.Sort(As,(x,y)=>(int)(y-x));
        long sum = As.Sum();

        long ans = 1;

        for (int i = 0; i < N-1; i++)
        {
            sum -= As[i];

            if (As[i] <= 2 * sum) ans++;
            else break;
        }
        WriteLine(ans);
    }



}