4. [10 marks] You have N items for sale, numbered from1 to N. Alice is willing t
ID: 3706128 • Letter: 4
Question
4. [10 marks] You have N items for sale, numbered from1 to N. Alice is willing to pay ai] > 0 dollars for item i, and Bob is willing to pay bli] >0 dollars for te. Alice is willing to buy no more than A of your items, and Bob is willing to buy no more than B of your items. Additionally, you must sell each item to either Alice or Bob, but not both, so you may assume that N A+ B. Given N, A, B, a[1..N and b..N], show that you can determine the maximum total amount of money you can earn in O(N log N) time. Hint: Suppose ? = A+ B and pretend you wish to sell all items to Alice, but must choose B of them to give to Bob instead. Which ones do you want to give to Bob first? Then extend your approach to handle NExplanation / Answer
Solution:
The algorithm is given below:
Algorithm:
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.