跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F2350. Buy One, Get One Free

    ID: 2356 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 10 上传者: 标签>动态规划贪心算法思想挑战难度共享题库Codeforces英文题面题目来源题面语言

Buy One, Get One Free

题目描述

F. Buy One, Get One Free
time limit per test
5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 109.

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 C++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples
Input
6
3 4 5 3 4 5
Output
14
Input
5
5 5 5 5 5
Output
25
Input
4
309999 6000 2080 2080
Output
314159
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.


题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 1973 题。保留原作者与原赛事署名。