Excellence
InterviewTime limit2sMemory limit256 MB
Pair all students into teams of two so the smallest team rating sum is as large as possible.
- Level
Medium4 of 10
- Topics
- Greedy, Sorting, Two pointers
- Solved
- No attempts yet
Problem
The World Coding Federation is setting up a large online programming tournament for teams of two programmers. Judge David puts together the teams of the southeastern delegation. Every student joins exactly one team of two students, and the number of students who want to compete is even, so nobody is left out. David wants every team he sends to the tournament to reach some minimum total rating. The total rating of a team is the sum of the ratings of its two members.
Find the maximum value such that David can form the teams so that every team has a total rating of at least .
Input
The first line contains a positive integer , the number of students who want to enter the tournament (, is even). Each of the next lines contains one integer , the rating of student ().
Output
Print on a single line the maximum value such that David can form teams where every team has a total rating of at least .