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.

icon
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.

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.
Transcribed Image Text: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.
Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Similar questions