Forming Badminton Doubles Teams
InterviewTime limit1sMemory limit1024 MB
Partition some people into groups of four to minimize the total skill gap per group, and list anyone left out; output any valid choice.
- Level
Medium6 of 10
- Topics
- Sorting, Dynamic programming, Greedy, Array
- Solved
- No attempts yet
Problem
Members of the badminton club at Korea University want to play badminton. So that everyone can play at the same time and have fun, they want to form doubles teams as follows, taking each member's skill into account.
In badminton doubles, two players pair up to face another pair, so a game involves a total of four people, two on each side. Every person's badminton skill can be represented as a positive integer. For each team, define its skill gap as (maximum skill) - (minimum skill). People of similar skill should play together to have fun, so the smaller the skill gap, the more fun the game is. Apart from the skill gap, not playing badminton at all is the least fun, so as many teams as possible must be formed.
Since there are many people right now, several teams must be formed, and the sum of the skill gaps of all teams must be minimized. However, the number of participants may not be a multiple of 4, so some people may not get to play.
Write a program that, when forming teams so that the sum of the skill gaps is minimized, finds the minimum value of that sum and determines who does not get to play badminton.
Input
The first line gives the number of participants . ()
The second line gives integers representing the badminton skills, separated by spaces. ()
Skills are given in order of person number, so the skill of person is , and numbering starts at 0.
Output
On the first line, print the minimum value of the sum of the skill gaps.
From the second line, print the numbers of the people who do not get to play badminton, one per line. If there are several valid cases, print any one of them.