CF160A.Twins
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 _a_1, _a_2, ..., a__n. 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 $ 枚面值任意的硬币 $ a_1,,a_2,,\dots,,a_n $。但由于时间紧迫,妈妈没来得及把硬币分给你们俩,只匆匆留下一张纸条,要求你们把钱平分。
当你醒来后,发现了妈妈留下的硬币,并读到了这张纸条。“但为什么要平分呢?”——你心想。毕竟,你的双胞胎此刻还在熟睡,对此一无所知。于是你决定这么做:从这些硬币中选出一个子集归自己所有,使得你所选硬币的面值总和严格大于留给双胞胎的剩余硬币的面值总和。然而,你又明智地想到:若你拿走的硬币太多,双胞胎事后可能会察觉其中的猫腻。因此,你决定采用如下策略以避免引起怀疑:在保证所选硬币面值总和严格大于剩余硬币面值总和的前提下,取最少数量的硬币。基于此,请确定:按上述方式分配硬币时,你至少需要取多少枚硬币?
输入格式
The first line contains integer n (1 ≤ n ≤ 100) — the number of coins. The second line contains a sequence of n integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 100) — the coins' values. All numbers are separated with spaces.
第一行包含一个整数 n(1≤n≤100)—— 表示硬币的数量。
第二行包含一个由 n 个整数 a1,a2,…,an(1≤ai≤100)组成的序列 —— 表示各硬币的面值。所有数字之间用空格分隔。
输出格式
In the single line print the single number — the minimum needed number of coins.
在单行中输出一个整数——所需的最少硬币数量。
输入输出样例
输入#1
2 3 3
输出#1
2
输入#2
3 2 1 2
输出#2
2
说明/提示
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 和 6。这些方案均不满足要求,因为你的硬币面值之和必须严格大于你双胞胎的硬币面值之和。
在第二个样例中,仅取 1 枚硬币同样不够。你可以选择面值为 1, 2 的硬币,或面值为 2, 2 的硬币。无论哪种情况,所需硬币的最少数量均为 2。
输入解题思路,AI测评打分。不知道怎么写?