All problems

Problem 987

Minimize Maximum Pair Sum in Array

Medium · 20 pts · Array, Two Pointers, Greedy, Sorting

Problem

The array has an even length 2N. Split it into N pairs, using every element exactly once, so that the largest pair sum is as small as possible, and print that largest pair sum. Sort the array and pair the smallest element with the largest, the second smallest with the second largest, and so on; any other pairing can only make the worst pair larger.

Input

The first line contains 2N. The second line contains the 2N integers.

Output

Print the minimized maximum pair sum.

Constraints

2 <= 2N <= 100000; 2N is even; 1 <= A[i] <= 10^5

Example input

4
3 5 2 3

Example output

7

Explanation

For 3 5 2 3, pairing (2, 5) and (3, 3) gives pair sums 7 and 6, so the maximum is 7. Every other pairing has a pair sum of 8.

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

Previous: Maximum Length of Subarray With Positive Product Next: Rabbits in Forest