Question: Question 2 : ( 3 0 Marks ) In a candy shop, there are n bars of chocolates with different prices in $ , assume

Question 2: (30 Marks) In a candy shop, there are n bars of chocolates with different prices in $ , assume Prices =7,1,3,1,4,10,8. You have some coupons that allow you to buy a specific number of bars, where the cheapest bar will be free, assume Coupons =[3,4]. If you want to buy all bars of chocolate, which coupon will you choose to pay as minimum as possible? Given the above inputs, you have two options: If you choose to use the first coupon (i.e.,3), you will probably choose the most 3 expensive bars: [ the bars with prices $7,$10, and $8] and according to the rule you will pay for them $18 only (remember that the cheapest bar will be free), then you will pay the price of all the remaining bars: [the bars with prices $1,$3,$1, and $4 ending up with a total price of $27. If you choose to use the second coupon (i.e.,4), you will probably choose the most 4 expensive bars: [ the bars with prices $7,$4,$10, and $8] and according to the rule you will pay for them $25 only (remember that the cheapest bar will be free), then you will pay the price of all the remaining bars: [the bars with prices $1,$3, and $1] ending up with a total price of $30. Accordingly, you must choose the first coupon (i.e.3) in order to pay as minimum as possible Examples: \table[[,Input,output],[Test case 1:,\table[[Prices =[1,5,6,8,2,7,10,8,12,3,10](Note: please bython code without predefine functions as sum or min)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!