Question: Question 2 : ( 3 0 Marks ) In a candy shop, there are n bars of chocolates with different prices in $ , assume
Question : Marks In a candy shop, there are n bars of chocolates with different prices in $ assume Prices You have some coupons that allow you to buy a specific number of bars, where the cheapest bar will be free, assume Coupons 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 ie you will probably choose the most expensive bars: the bars with prices $$ and $ and according to the rule you will pay for them $ only remember that the cheapest bar will be free then you will pay the price of all the remaining bars: the bars with prices $$$ and $ ending up with a total price of $ If you choose to use the second coupon ie you will probably choose the most expensive bars: the bars with prices $$$ and $ and according to the rule you will pay for them $ only remember that the cheapest bar will be free then you will pay the price of all the remaining bars: the bars with prices $$ and $ ending up with a total price of $ Accordingly, you must choose the first coupon ie in order to pay as minimum as possible Examples: tableInput,outputTest case :tablePrices 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
