cswork / OA打开练习工作台

AmazonOA #81

Maximum System Memory Capacity (Primary-Backup Pairing)

估计简单可在线判题

考点(AI 标注)贪心调度原地数组

An even number of servers form primary-backup pairs one to one, and in each pair the backup's memory must be ≤ the primary's memory. Maximize the total memory of all primaries; note that the direction of the inequality in this problem follows the statement text.

输入格式

The first line contains an even n (2..200000), and the second line contains n memory values (1..10⁹).

输出格式

Output a single integer answer.

样例 1

输入:

4
1 2 3 4

输出:

7

样例 2

输入:

2
8 8

输出:

8

样例 3

输入:

4
2 2 9 10

输出:

19

样例说明

Example 1: 3 and 4 are primaries, paired with 1 and 2, for a total of 7. Example 2: equality is allowed, so the primary memory is 8. Example 3: 9 and 10 are primaries and the two 2s are backups, for a total of 19.