Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

algorithms programing in c language Shopping is FUN Kang Ji Sung very loves shopping. Whenever shops have a discount event, he completely goes crazy and

algorithms
programing in c language
image text in transcribed
image text in transcribed
image text in transcribed
Shopping is FUN Kang Ji Sung very loves shopping. Whenever shops have a discount event, he completely goes crazy and wants to buy all items in the shops. You are his best friend; you cannot stop him from shopping but you can give him a shopping strategy to save his money. Today, a shop offers a very good deal "Buy 3 only pay 2 with a rule that in one bill only the cheapest ones get free. Your job is to help him find the maximum discount he can get. Example: - Your friend wants to buy 7 items, costing 350000, 14400000, W300000 ?100000, \ 150000, ?200000, and \250000. -If he buys all items in one bill, he gets 2 free items which are the cheapest ones of W100000 and 150000. Consequently, he gets the discount of 250000 and must pay ?1500000 If he buys the items separately, he may get a bigger discount. For instance, he separates the items in three bills as follow The first bills: 3 items ?400000, ?300000, and \\250000 ? \250000 discount. o The second bill: 2 items W350000, 200000 and W100000100000 discount. o The third bill: 1 item 150000no discount. o Eventually, he gets the total discount of 350000 and must pay #1400000 Input is read from the text file shopping.inp consisting of The first line is the number of items he buys The second line is the list of prices of items Output is written to the text file shopping.out consisting of ONLY ONE NUMBER which is the maximum discount he can get. Example: shopping.inp shopping.out 400000 100000 400000 200000 350000 300000 250000

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions

Question

How do behavioral biases affect the efficiency of market prices?

Answered: 1 week ago

Question

9-13. What techniques are used to capture the readers attention?

Answered: 1 week ago

Question

What is your intention in communicating this message?

Answered: 1 week ago