Group Project
InterviewTime limit1sMemory limit512 MB
Split N students with distinct IDs into pairs and one triple so that the sum of each team's max-min ID gap is minimized.
- Level
Medium5 of 10
- Topics
- Sorting, Dynamic programming
- Solved
- No attempts yet
Problem
A class of students must be split into teams for a group project. Every student must belong to exactly one team. A team should normally have 2 members, but since is odd, exactly one team has 3 members. The other teams have 2 members each.
A successful group project needs a friendly atmosphere. Each student has a unique student ID. The awkwardness of a team is the difference between the largest and smallest student IDs in that team.
Form the teams so that the sum of awkwardness over all teams is minimized.
Input
The first line contains the number of students . (, is odd)
The second line contains integers , separated by spaces, where is the student ID of the -th student. () All are distinct.
Output
Print the minimum possible sum of awkwardness over all formed teams.