You have m dollars and a group of n friends. For each friend 1 ≤ i ≤n, you know the price P[i] of the piece of candy that would make your friend happy. You want to find a way to distribute the m dollars such that as many of your friends as possible are happy. Design an O(n log n) time greedy algorithm to find how much money you will allocate each friend.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 18SA
icon
Related questions
Question

 You have m dollars and a group of n friends. For each friend 1 ≤ i ≤n, you know the price P[i] of the piece of candy that would make your friend happy. You want to find a way to distribute the m dollars such that as many of your friends as possible are happy. Design an O(n log n) time greedy algorithm to find how much money you will allocate each friend.

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Time complexity
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning