eolymp
bolt
Try our new interface for solving problems
Problems

Special Deal

Special Deal

\includegraphics{https://eolympusercontent.com/images/ggcnhfsv3l24t44iuvdkfsv1m4.gif} There’s a special deal on CodeAny platform: “Select $3$ video courses, pay for the $2$ most expensive ones.” This means that for every set of $3$ courses chosen, the cheapest one is free. Customers can choose more than $3$ courses, and depending on how they organize them into groups of three, they can get the cheapest course in each group for free. For instance, if a customer selects courses with prices: $10, 3, 2, 4, 6, 4$ and $9$, and arranges them into groups like $(10, 3, 2), (4, 6, 4)$, and $(9)$, they’ll receive the course priced at $2$ from the first group, and the course priced at $4$ from the second group for free. The third group won’t yield any free courses because it contains only one course. The employee on CodeAny platform aims to minimize the total cost for each customer. Given the course prices, the task is to assist the employee in organizing the courses into groups in the most cost-effective way possible. It’s not necessary for each group to contain exactly $3$ courses, but the number of courses in a group must range from $1$ to $3$, inclusive. \InputFile The first line contains the integer $n~(1 \le n \le 10^5)$, the number of video courses the customer bought. Each of the following $n$ lines contains a single integer $c_i~(1 \le c_i \le 10^5)$, the price of each video course. \OutputFile Print required minimum price. \Scoring This task consists of the following subtasks. If all tests of a subtask are passed, you will earn points for that subtask. \begin{enumerate} \item ($35$ points): $n \le 1000$; \item ($65$ points): $no~additional~constrains$; \end{enumerate}
Time limit 1 second
Memory limit 128 MiB
Input example #1
4
3
2
3
2
Output example #1
8
Input example #2
6
6
4
5
5
5
5
Output example #2
21
Source 2024, IDDA Cup, March 31, Problem C