a784: Twins ( 雙胞胎 )
Tags : 900 greedy sortings
Accepted rate : 26人/27人 ( 96% ) [非即時]
評分方式:
Tolerant

最近更新 : 2022-07-27 08:36

Content

Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.

Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, n coins of arbitrary values a1, a2, ..., an. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally.

As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner.

想像一下,你有一個雙胞胎兄弟或姐妹。擁有一個和你一模一樣的人似乎很不尋常。很難說擁有另一個自我是好事還是壞事。如果你確實有一個雙胞胎,那麼你很清楚它是什麼樣的。

現在讓我們想像一下您家中一個典型的早晨。你還沒起床,媽媽已經去上班了。她太倉促了,差點忘了給兩個心愛的孩子留點錢去學校食堂買午餐。她在錢包裡摸索,發現了一些硬幣,或者準確地說,是 n 個任意值 a1, a2, ..., an 的硬幣。但是因為媽媽時間不多了,她沒有給你們兩個分硬幣。所以她草草寫了一張紙條,要求你平分錢。

當你醒來時,你找到了媽媽的硬幣並閱讀了她的便條。 “可是為什麼要平分錢呢?” - 你以為。畢竟,你的雙胞胎正在睡覺,他什麼都不知道。所以你決定這樣做:為自己挑選一些硬幣的子集,這樣你的硬幣的價值總和嚴格大於你的雙胞胎將擁有的剩餘硬幣的價值總和。但是,您正確地認為,如果您拿走太多硬幣,雙胞胎就會懷疑是騙局。因此,您決定堅持以下策略以避免懷疑:您取最少數量的硬幣,其價值總和嚴格大於剩餘硬幣的價值總和。在此基礎上,確定以所述方式劃分它們所需的最少硬幣數量。

Input

The first line contains integer n (1 ≤ n ≤ 100) — the number of coins. The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 100) — the coins' values. All numbers are separated with spaces.

第一行包含整數 n (1 ≤ n ≤ 100) — 硬幣的數量。 第二行包含一個由 n 個整數組成的序列 a1, a2, ..., an (1 ≤ ai ≤ 100) — 硬幣的值。 所有數字都用空格分隔。

Output

In the single line print the single number — the minimum needed number of coins.

在單行中打印單個數字——最少需要的硬幣數量。

Sample Input #1
2
3 3
Sample Output #1
2
Sample Input #2
3
2 1 2
Sample Output #2
2
測資資訊:
記憶體限制: 64 MB
公開 測資點#0 (5%): 0.5s , <1K
公開 測資點#1 (5%): 0.5s , <1K
公開 測資點#2 (5%): 0.5s , <1K
公開 測資點#3 (5%): 0.5s , <1K
公開 測資點#4 (5%): 0.5s , <1K
公開 測資點#5 (5%): 0.5s , <1K
公開 測資點#6 (5%): 0.5s , <1K
公開 測資點#7 (5%): 0.5s , <1K
公開 測資點#8 (5%): 0.5s , <1K
公開 測資點#9 (5%): 0.5s , <1K
公開 測資點#10 (5%): 0.5s , <1K
公開 測資點#11 (5%): 0.5s , <1K
公開 測資點#12 (5%): 0.5s , <1K
公開 測資點#13 (5%): 0.5s , <1K
公開 測資點#14 (5%): 0.5s , <1K
公開 測資點#15 (5%): 0.5s , <1K
公開 測資點#16 (5%): 0.5s , <1K
公開 測資點#17 (5%): 0.5s , <1K
公開 測資點#18 (5%): 0.5s , <1K
公開 測資點#19 (5%): 0.5s , <1K
Hint :

In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.

In the second sample one coin isn't enough for us, too. You can pick coins with values 1, 2 or 2, 2. In any case, the minimum number of coins equals 2.

在第一個樣本中,您必須取 2 個硬幣(您和您的雙胞胎的總和分別等於 6, 0)。 如果你拿 1 個硬幣,你得到總和 3, 3。如果你拿 0 個硬幣,你得到總和 0, 6。這些變體不能滿足你,因為你的總和應該嚴格高於你雙胞胎的總和。

在第二個示例中,一枚硬幣對我們來說也不夠。 您可以選擇值為 1, 2 或 2, 2 的硬幣。無論如何,硬幣的最小數量等於 2。

Tags:
900 greedy sortings
出處:
Codeforces Round #111 [管理者:
lamkinun@gma... (Kinda Lam)
]


ID User Problem Subject Hit Post Date
沒有發現任何「解題報告」