CF335F.Buy One, Get One Free

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 nn ( 1<=n<=5000001<=n<=500000 ), the number of pies you wish to acquire. Following this is a line with nn integers, each indicating the cost of a pie. All costs are positive integers not exceeding 10910^{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.

首页