301777: CF335F. Buy One, Get One Free

Memory Limit:256 MB Time Limit:5 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Buy One, Get One Free

题意翻译

你到一家正在进行特价活动的馅饼店买馅饼。规则是每全价购买一个馅饼,都可以免费得到一个价格严格更低的馅饼。 求出为所有馅饼支付的最小花费。 $n \leq 5\times 10^5$,$1\leq a_i \leq 10^9$。

题目描述

A nearby pie shop is having a special sale. For each pie you pay full price for, you may select one pie of a strictly lesser value to get for free. Given the prices of all the pies you wish to acquire, determine the minimum total amount you must pay for all of the pies.

输入输出格式

输入格式


Input will begin with an integer $ n $ ( $ 1<=n<=500000 $ ), the number of pies you wish to acquire. Following this is a line with $ n $ integers, each indicating the cost of a pie. All costs are positive integers not exceeding $ 10^{9} $ .

输出格式


Print the minimum cost to acquire all the pies. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

输入输出样例

输入样例 #1

6
3 4 5 3 4 5

输出样例 #1

14

输入样例 #2

5
5 5 5 5 5

输出样例 #2

25

输入样例 #3

4
309999 6000 2080 2080

输出样例 #3

314159

说明

In the first test case you can pay for a pie with cost 5 and get a pie with cost 4 for free, then pay for a pie with cost 5 and get a pie with cost 3 for free, then pay for a pie with cost 4 and get a pie with cost 3 for free. In the second test case you have to pay full price for every pie.

Input

题意翻译

你到一家正在进行特价活动的馅饼店买馅饼。规则是每全价购买一个馅饼,都可以免费得到一个价格严格更低的馅饼。 求出为所有馅饼支付的最小花费。 $n \leq 5\times 10^5$,$1\leq a_i \leq 10^9$。

加入题单

上一题 下一题 算法标签: