IQ
InterviewTime limit1sMemory limit64 MB
Pair 2n numbers into n pairs so the difference between the largest and smallest pair sums is minimized, and print that difference.
- Level
Easy3 of 10
- Topics
- Sorting, Greedy, Brute force, Array
- Solved
- No attempts yet
Problem
newbie students came to competitive programming practice. Each student is characterized by his IQ level: the -th student has IQ .
The coach wants to break students up into teams of two people. Each team is characterized by a team IQ that is equal to the sum of the team members IQ levels. For example, if a team is formed from students and , the team IQ is . One team is stronger than the other if its team IQ is greater.
By the coach's opinion, practice will be much more productive if the difference between team IQs of the strongest and the weakest team is as small as possible. Help the coach determine the minimum value for which it is possible to form teams in such a way that difference of team IQs between the strongest and the weakest team is equal to .
Input
The first line contains integer ().
The second line contains integers, the -th of which is equal to the IQ of the -th student (, ).
Output
Output the minimum value for which the forming of teams is possible.