Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ACM There is a promotional offer in a bookstore Take 3, pay for the 2 more expensive ones. So, each customer who picks 3 books

ACM

There is a promotional offer in a bookstore Take 3, pay for the 2 more expensive ones. So, each customer who picks 3 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:10,3,2,4,6,4,9

. If he arranges them into groups:(10,3,2),(4,6,4)and(9), he will get the book priced2from the first group for free and the book priced4

from the second group. We can see that he wont 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 doesnt have to arrange the books into groups so that each group contains exactly 3 books, but the number of books in a group needs to be between 1 and 3, inclusively.

Input

The first line of input contains the integerN

(1N100000), the number of books the customer bought. Each of the followingNlines contains a single integerCi(1Ci100000), the price of each book

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

Guide To Client Server Databases

Authors: Joe Salemi

2nd Edition

1562763105, 978-1562763107

More Books

Students also viewed these Databases questions