All problems

Problem 824

Array Partition

Easy · 10 pts · Array, Greedy, Sorting

Problem

The array has 2N integers. Group them into N pairs so that the sum of the minimums of the pairs is as large as possible, and print that sum. Sorting is the key: pairing each element with its neighbour in sorted order wastes the least, so the answer is the sum of the elements at even positions (0, 2, 4, ...) of the sorted array.

Input

The first line contains 2N, the size of the array. The second line contains the 2N integers.

Output

Print the maximum possible sum of the pair minimums.

Constraints

2 <= 2N <= 100000; 2N is even; -10^4 <= A[i] <= 10^4

Example input

4
1 4 3 2

Example output

4

Explanation

Sorted, 1 4 3 2 is 1 2 3 4. Pairing (1,2) and (3,4) gives minimums 1 and 3, a sum of 4, which beats the other pairings.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Check If N and Its Double Exist Next: Element Appearing More Than 25% in a Sorted Array