MemSQL start[c]up Round 2 - online version
F
Buy One, Get One Free
Codeforces
3000
原题
← E→
翻译中…

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

翻译中…

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}$.

翻译中…

Output

翻译中…

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.

翻译中…

Note

翻译中…

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 #1
6
3 4 5 3 4 5
Output #1
14
InputCopy OutputCopy
Input #2
5
5 5 5 5 5
Output #2
25
InputCopy OutputCopy
Input #3
4
309999 6000 2080 2080
Output #3
314159
InputCopy OutputCopy
题目信息
题号
335F
时间限制
5 s
内存限制
256 MB
标签
动态规划
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。