You have m dollars and a group of n friend. 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.
You have m dollars and a group of n friend. 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.
Related questions
Question
I need the algorithm, proof of correctness and runtime analysis for the problem. No code necessary ONLY algorithm. And runtime should be O(n log n) as stated in the question.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 1 images