here is a promotional offer in a bookstore "Take 3, pay for the 2 more expensive ones". So, each custon ho picks 33 books gets the cheapest one for free. Of course, the customer can take even more books epending on the way the books are arranged into groups of three, get the cheapest one in each group ree. or example, let the prices of the books taken by the customer be: 2,3,4,4,6,9,102,3,4,4,6,9,10. If he arran nem into the groups (10,3,2)(10,3,2), (4,6,4)(4,6,4) and (9)(9), he will get the book priced 22 from the first roup for free and the book priced 44 from the second group. We can see that he will not get anything ree from the third group because it contains only one book. he lady working in the bookstore is well-intentioned and she always wants to lower the price for each ustomer as much as possible. For given book prices, help the lady arrange the books into groups in the est way possible, so that the total price the customer has to pay is minimal. lease note: The lady doesn't have to arrange the books into groups so that each group contains exactl ooks, but the number of books in a group needs to be between 11 and 33, inclusively. nput he first line of input contains the integer NN (1

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter4: Selection Structures
Section: Chapter Questions
Problem 14PP
icon
Related questions
Question

In C please

C Program
There is a promotional offer in a bookstore "Take 3, pay for the 2 more expensive ones". So, each customer
who picks 33 books gets the cheapest one for free. Of course, the customer can take even more books and,
depending on the way the books are arranged into groups of three, get the cheapest one in each group for
free.
For example, let the prices of the books taken by the customer be: 2,3,4,4,6,9,102,3,4,4,6,9,10. If he arranges
them into the groups (10,3,2)(10,3,2), (4,6,4)(4,6,4) and (9)(9), he will get the book priced 22 from the first
group for free and the book priced 44 from the second group. We can see that he will not get anything for
free from the third group because it contains only one book.
The lady working in the bookstore is well-intentioned and she always wants to lower the price for each
customer as much as possible. For given book prices, help the lady arrange the books into groups in the
best way possible, so that the total price the customer has to pay is minimal.
Please note: The lady doesn't have to arrange the books into groups so that each group contains exactly 33
books, but the number of books in a group needs to be between 11 and 33, inclusively.
Input
The first line of input contains the integer NN (1<N<100 0001<N<100 000), the number of books the
customer bought. Each of the following NN lines contains a single integer CiCi (1sCis100 0001sCis100
000), the price of each book.
Output
The first and only line of output must contain the required minimal price.
Sample Input 1
Sample Output 1
4
8.
3
2
3
2
Sample Input 2
Sample Output 2
21
5
Transcribed Image Text:C Program There is a promotional offer in a bookstore "Take 3, pay for the 2 more expensive ones". So, each customer who picks 33 books gets the cheapest one for free. Of course, the customer can take even more books and, depending on the way the books are arranged into groups of three, get the cheapest one in each group for free. For example, let the prices of the books taken by the customer be: 2,3,4,4,6,9,102,3,4,4,6,9,10. If he arranges them into the groups (10,3,2)(10,3,2), (4,6,4)(4,6,4) and (9)(9), he will get the book priced 22 from the first group for free and the book priced 44 from the second group. We can see that he will not get anything for free from the third group because it contains only one book. The lady working in the bookstore is well-intentioned and she always wants to lower the price for each customer as much as possible. For given book prices, help the lady arrange the books into groups in the best way possible, so that the total price the customer has to pay is minimal. Please note: The lady doesn't have to arrange the books into groups so that each group contains exactly 33 books, but the number of books in a group needs to be between 11 and 33, inclusively. Input The first line of input contains the integer NN (1<N<100 0001<N<100 000), the number of books the customer bought. Each of the following NN lines contains a single integer CiCi (1sCis100 0001sCis100 000), the price of each book. Output The first and only line of output must contain the required minimal price. Sample Input 1 Sample Output 1 4 8. 3 2 3 2 Sample Input 2 Sample Output 2 21 5
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Probability Problems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning