W: Maximum number of coffee pounds that the delivery van can carry. n: Number of different types of coffee that can be shipped. (Let's call these n coffee types T1, ..., Tn.) weight: a 1-dimensional array of size n of integers cost_per_pound: a 1-dimensional array of size n of reals such that for each i, 1 ≤ i ≤ n: weight[i]= maximum number of pounds of coffee type Ti that can be shipped cost_per_pound[i]= cost of one pound of type Ti coffeeAssume that the business is going so well that the company has more coffee to ship than what the delivery van can carry. Hence, your algorithm needs to determine what coffee types, and how much coffee of each of these types, to pack in the van to maximize the total cost of the coffee shipped. That is, your algorithm needs to produce as output:
ship: 1-dimensional array of size n of reals such that for each i, 1 ≤ i ≤ n: ship[i]= amount in pounds of coffee type Ti included in the shipping (this amount doesn't have to be an integer. For example, your algorithm might find that for a certain type of coffee Ti the best amount to pack is 3.75 pounds. In this case the cost of ship[i] would be 3.75*cost_per_pound[i]. Or if your program determines that this coffee type shouldn't be shipped at all, then ship[i]=0.) satisfying: ship[i] &le weight[i], Σni=1 ship[i]≤ W, and Σni=1 ship[i]*cost_per_pound[i] is as large as possible.You assignment is to write a greedy algorithm (in pseudo-code) to solve this problem. With this goal in mind, follow the steps below.
W=100, n=5. T1 T2 T3 T4 T5 weight: 10 20 30 40 50 cost: 20 30 66 40 60 cost_per_pound: 2.0 1.5 2.2 1.0 1.2
------------------------------------ 6 2 2 1 1.0 2 3 4.0 2 4 2.0 1 0 3.0 1 3 1.0 4 3 2.0 4 5 3.0 3 0 1.0 3 5 2.0 ------------------------------------Please note that there is a newline character after "3 5 2.0".
--------- --------- 4 ---> | 3 | 2.0 | ---> | 5 | 3.0 | --------- ---------
Your program should implement Heaps and based on them, Priority Queues, satisfying all the specifications below.
5 4 2->1->3->5