Tournament
InterviewTime limit1sMemory limit1024 MB
Remove one student as host and pair the other n-1 students so that the gap between the largest and smallest pair sums is as small as possible.
- Level
Medium5 of 10
- Topics
- Sorting, Greedy, Prefix sum
- Solved
- No attempts yet
Statement
The linguistic game "Hat" is played by several pairs of players. Also there should be one host of the game.
A teacher plans to organize a "Hat" tournament in their class consisting of students, where is odd. To do this, the teacher wants to split the students into pairs and leave one student to be the host.
Number the students from to . Student has a "Hat" skill value of . The skill of a pair is the sum of the two students' skill values.
To make the tournament as fair as possible, the teacher wants the difference between the maximum and minimum pair skills to be as small as possible. Help the teacher choose the host and split the other students into pairs to reach this goal.
Input
The first line contains an integer , the number of students (, is odd).
The second line contains integers ().
Output
Print one number: the smallest possible difference between the maximum and minimum skills of the pairs.