You are given some coins. You have to take some coins from the given coins such that the sum of the coins you took have a value strictly larger than the sum of the rest of the coins. However, you have to take minimum number of coins while satisfying this condition

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

9. You are given some coins. You have to take some coins from the given coins such that the sum of the coins
you took have a value strictly larger than the sum of the rest of the coins. However, you have to take
minimum number of coins while satisfying this condition
Input
In the first line, you are given n (n<=100), the number of integer numbers. In the next line, you will be given n
integers, separated by spaces.
Output
Output one number, the minimum number of coins you need to take to have a larger sum than the sum of the
coins you did not take.
Input Output
2
3 3
                       2
3
2 1 2
                      2
6
4 2 1 2 1 1
                      2
In the first sample you will have to take 2 coins. If you take 1 coin, you get sum 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 than the other sum.
In the second sample one coin isn't enough for you, too. You can pick coins with values 1, 2 or 2, 2. In any case,
the minimum number of coins equals 2.
In third sample, if you take the coin with value 4 and 2. You have a sum of 6, Rest of them will have a sum of 5.
Answer is 2. And you can’t to this in less than 2 coin.

Expert Solution
steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY