cswork / OA打开练习工作台

AmazonOA #274

Maximum System Memory Capacity

估计简单可在线判题

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

Choose an even number of the n servers: half of them are primaries and half are backups. Each server is used only once, and every primary is paired with a backup whose capacity is at least its own. The contribution is the sum of all primary capacities; find its maximum. You do not have to use all servers.

输入格式

The first line contains n and the second line contains memory. 2≤n≤200000, 1≤memory[i]≤10^9. The original constraints mistakenly named the variable size, but their original side note clearly refers to memory; this site uses one name throughout.

输出格式

Output a single integer, the answer.

样例 1

输入:

4
1 2 1 2

输出:

3

样例 2

输入:

3
1 2 1

输出:

1

样例 3

输入:

5
2 4 3 1 2

输出:

5

样例说明

The answers are 3, 1 and 5 respectively. In the third example, pair 4 with 3 and 2 with 2; the primary capacity is 3+2=5, and 1 is left unused.