Problem Statement
Several people want to play hockey, so they use the following algorithm to split themselves into teams. First, there are teams captains, numbered from 1 to teams. The captains select players for their teams, always trying to pick the strongest player who hasn't been picked yet. The draft process is split into several rounds, which are enumerated starting from 1. Captain 1 starts round 1 of the draft by picking the strongest available player, followed by captain 2 and all other captains in order of ascending indices. When captain teams makes his pick, round 1 is over. If not all the players were picked, the draft continues with round 2. In round 2, all captains make their picks in the reverse order - so captain teams starts the round, and captain 1 ends it. Rounds 3, 5 and all other rounds with odd numbers go similar to round 1, while all rounds with even numbers go similar to round 2. For example, if there are 4 captains, they'll pick players in the following order: 1, 2, 3, 4, 4, 3, 2, 1, 1, 2, 3, ... The draft is over when all players are picked.
You will be given a
Definition
- Class:
- BuildATeam
- Method:
- maximalStrength
- Parameters:
- int[], int
- Returns:
- int
- Method signature:
- int maximalStrength(int[] skills, int teams)
- (be sure your method is public)
Constraints
- skills will contain between 2 and 50 elements, inclusive.
- Each element of skills will be between 1 and 100, inclusive.
- teams will be between 2 and 50, inclusive.
- The number of elements in skills will be an integer multiple of teams.
Examples
{10, 9, 7, 3, 3, 2}
3
Returns: 12
The players will be split into the following teams: Team 1 2 3 Round 1 10 9 7 Round 2 2 3 3 Teams 1 and 2 both have a strength of 12, while team 3 has a strength of 10.
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
4
Returns: 21
Team 1 has the maximal strength of 12 + 5 + 4 = 21.
{10, 10, 10, 9, 8, 8, 3, 1}
2
Returns: 31
Players 1, 4, 5 and 8 (with strengths of 10, 9, 8 and 1) go to team 1, while the other four players (with strengths of 10, 10, 8 and 3) go to team 2. The total strength of team 1 is 28, and the total strength of team 2 is 31.
{10, 8, 10, 1, 10, 9, 3, 8}
2
Returns: 31
The same people as in example 2, but placed in another order.
{98, 19, 11, 11, 11, 11, 23, 55, 1, 4, 3, 4, 6, 8}
7
Returns: 99
{2, 3, 4, 6, 9, 12, 14, 15, 15, 15, 17, 17, 19, 22, 26, 27, 32, 35, 36, 36, 38, 41, 45, 45, 50, 51, 52, 52, 60, 64, 69, 70, 70, 72, 80, 81, 81, 82, 83, 84, 85, 88, 91, 97}
44
Returns: 97
{1, 7, 11, 15, 18, 20, 33, 34, 34, 36, 39, 41, 45, 46, 54, 55, 64, 70, 78, 80, 81, 88, 96, 97, 98, 99}
26
Returns: 99
{5, 10, 12, 13, 17, 19, 23, 25, 26, 28, 31, 31, 34, 39, 42, 45, 46, 49, 52, 52, 55, 58, 62, 65, 69, 69, 75, 81, 85, 87, 92, 98}
32
Returns: 98
{2, 3, 3, 6, 7, 8, 9, 11, 19, 20, 20, 25, 25, 25, 26, 26, 32, 40, 41, 41, 42, 43, 45, 45, 45, 46, 46, 57, 59, 62, 63, 64, 65, 68, 69, 70, 75, 76, 78, 79, 81, 83, 88, 90, 91, 91, 91, 97, 98}
49
Returns: 98
{1, 3, 4, 5, 5, 5, 6, 7, 9, 13, 15, 21, 22, 24, 26, 26, 27, 28, 28, 30, 44, 53, 59, 63, 65, 70, 70, 70, 70, 73, 74, 75, 77, 82, 88, 91, 96, 99}
38
Returns: 99
{3, 4, 7, 15, 16, 16, 19, 20, 20, 30, 31, 33, 38, 40, 40, 41, 45, 47, 47, 48, 48, 49, 52, 52, 52, 53, 55, 68, 72, 74, 75, 75, 77, 79, 81, 83, 84, 87, 91, 91, 91, 98}
42
Returns: 98
{6, 7, 7, 9, 11, 12, 19, 20, 25, 41, 61, 67, 68, 69, 70, 73, 74, 74, 77, 81, 84, 85, 89, 90, 90, 93, 96, 96, 97}
29
Returns: 97
{5, 7, 7, 11, 15, 16, 18, 22, 24, 25, 40, 52, 55, 56, 57, 65, 65, 67, 92, 97, 99}
21
Returns: 99
{1, 6, 8, 9, 10, 10, 13, 17, 25, 28, 29, 30, 31, 41, 42, 45, 45, 46, 47, 62, 64, 64, 65, 68, 70, 70, 71, 74, 75, 75, 79, 80, 86, 87, 91, 91, 95}
37
Returns: 95
{3, 5, 5, 14, 16, 18, 20, 20, 23, 32, 33, 34, 40, 45, 48, 49, 51, 54, 58, 61, 64, 65, 65, 67, 68, 68, 76, 79, 79, 82, 83, 84, 85, 99}
34
Returns: 99
{2, 4, 6, 10, 10, 11, 22, 23, 27, 28, 31, 33, 45, 49, 51, 52, 53, 54, 57, 71, 72, 73, 80, 80, 94, 96}
26
Returns: 96
{3, 6, 6, 14, 15, 16, 24, 44, 45, 48, 56, 57, 59, 77, 78, 83, 89, 91, 100, 100}
20
Returns: 100
{2, 4, 4, 10, 16, 16, 21, 22, 23, 25, 27, 29, 29, 30, 31, 36, 36, 41, 42, 43, 46, 47, 49, 52, 55, 55, 55, 57, 59, 62, 71, 73, 78, 79, 79, 80, 80, 84, 85, 87, 89, 92, 95, 95}
22
Returns: 107
{1, 2, 2, 6, 9, 14, 42, 48, 49, 54, 55, 70, 72, 79, 87}
15
Returns: 87
{2, 8, 9, 10, 11, 15, 19, 19, 23, 24, 29, 31, 34, 36, 36, 41, 44, 48, 52, 57, 58, 59, 60, 61, 66, 70, 76, 78, 79, 80, 80, 81, 83, 86, 86, 87, 88, 93, 94, 95}
40
Returns: 95
{4, 6, 7, 10, 10, 12, 17, 18, 22, 23, 25, 25, 26, 33, 35, 39, 40, 44, 46, 48, 50, 55, 55, 56, 59, 59, 60, 61, 64, 78, 80, 82, 84, 92, 99}
35
Returns: 99
{19, 20, 22, 23, 25, 25, 29, 38, 43, 48, 59, 63, 66, 71, 73, 73, 75, 75, 76, 82, 87, 94, 94, 99}
24
Returns: 99
{2, 4, 4, 4, 5, 9, 12, 25, 26, 29, 32, 35, 35, 37, 40, 43, 44, 48, 53, 60, 60, 61, 62, 64, 68, 73, 74, 79, 79, 84, 84, 86, 89, 90, 94, 95, 96, 97}
38
Returns: 97
{1, 8, 9, 10, 15, 17, 17, 19, 21, 21, 23, 26, 27, 29, 30, 32, 35, 43, 44, 44, 49, 55, 58, 59, 63, 63, 63, 64, 65, 66, 73, 80, 83, 93, 95, 95, 97, 97, 100}
39
Returns: 100
{1, 3, 5, 25, 33, 42, 47, 48, 55, 62, 81, 82, 84, 91, 92, 93, 95}
17
Returns: 95
{1, 2, 4, 11, 16, 17, 18, 19, 23, 28, 32, 33, 35, 36, 38, 38, 39, 40, 41, 44, 44, 45, 46, 50, 52, 52, 53, 54, 57, 60, 63, 69, 69, 70, 72, 72, 74, 83, 86, 86, 86, 88, 88, 90, 95}
45
Returns: 95
{4, 4, 5, 9, 9, 12, 17, 17, 18, 22, 30, 32, 37, 38, 40, 46, 50, 55, 55, 56, 57, 69, 76, 82, 82, 90, 93, 96, 96, 99, 99, 99}
16
Returns: 107
{1, 12, 19, 25, 27, 30, 31, 42, 43, 48, 49, 64, 71, 99}
14
Returns: 99
{5, 10, 12, 12, 14, 16, 16, 16, 19, 19, 27, 35, 35, 41, 43, 46, 48, 50, 53, 54, 55, 61, 67, 70, 71, 73, 74, 74, 74, 80, 83, 87, 88, 91, 92, 93, 94, 97, 99, 100}
40
Returns: 100
{1, 2, 3, 3, 6, 7, 11, 12, 14, 15, 15, 22, 25, 27, 31, 31, 33, 36, 36, 36, 38, 40, 44, 46, 47, 48, 49, 52, 56, 57, 62, 62, 63, 63, 64, 66, 67, 67, 71, 72, 76, 79, 88, 94, 95, 97, 98, 100}
16
Returns: 165
{4, 11, 19, 38, 41, 42, 46, 47, 52, 54, 54, 58, 65, 69, 70, 70, 73, 74, 74, 77, 83, 87, 90, 94, 97, 98}
2
Returns: 799
{1, 4, 4, 7, 7, 8, 11, 13, 17, 19, 22, 22, 23, 25, 26, 28, 29, 33, 35, 35, 38, 40, 44, 47, 51, 53, 53, 61, 62, 65, 66, 72, 73, 75, 81, 81, 82, 85, 86, 95, 96, 99}
3
Returns: 628
{2, 5, 7, 14, 16, 16, 16, 25, 28, 33, 39, 41, 45, 46, 63, 64, 66, 67, 69, 77, 81, 82, 82, 85, 87, 88, 91, 93, 93, 94}
3
Returns: 556
{15, 21, 22, 24, 37, 43, 44, 51, 63, 70, 77, 77, 87, 90, 91, 93, 95, 98, 98, 100}
4
Returns: 330
{6, 6, 7, 7, 9, 11, 14, 17, 20, 34, 34, 37, 40, 42, 43, 47, 48, 49, 56, 56, 63, 65, 75, 77, 78, 79, 81, 84, 85, 88, 92, 93, 93, 93, 94, 95, 98, 98, 98, 100}
4
Returns: 583
{1, 4, 9, 21, 36, 45, 45, 68, 70, 87, 87, 91, 92, 95}
2
Returns: 379
{5, 11, 12, 17, 18, 22, 22, 24, 25, 27, 27, 28, 28, 29, 33, 38, 39, 40, 42, 45, 47, 48, 49, 65, 66, 67, 68, 71, 73, 73, 78, 78, 80, 82, 83, 86, 87, 88, 90, 91, 92, 93, 97, 97, 99}
5
Returns: 512
{6, 9, 10, 37, 40, 42, 43, 49, 66, 74, 77, 90, 90, 90, 97}
5
Returns: 179
{3, 34, 44, 53, 75, 80, 81, 88, 90}
3
Returns: 197
{4, 6, 9, 12, 19, 29, 30, 30, 30, 32, 32, 35, 42, 42, 48, 50, 51, 53, 55, 66, 68, 74, 76, 77, 77, 78, 79, 79, 86, 87, 94, 98}
4
Returns: 417
{10, 1, 3, 10 }
2
Returns: 13
{4, 1, 4, 6, 4, 5 }
3
Returns: 9
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
50
Returns: 1
{98, 19, 11, 11, 11, 11, 23, 55, 1, 4, 3, 4, 6, 8 }
7
Returns: 99
{3, 1, 1, 3 }
2
Returns: 4
{1, 2, 3, 4, 5, 6, 7, 8 }
2
Returns: 18
{1, 10, 30, 20 }
2
Returns: 31
{10, 8, 10, 1, 10, 9, 3, 8 }
2
Returns: 31
{32, 1, 2, 4, 8, 16 }
2
Returns: 38
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }
3
Returns: 41
{10, 10, 10, 9, 8, 8, 3, 1 }
2
Returns: 31
{98, 19, 11, 11, 11, 11, 23, 55, 1, 4, 3, 4, 6, 8, 54, 23, 43, 90, 19, 43, 34, 13, 34, 15, 41, 22, 34, 11, 80, 80, 70, 67, 34, 37, 56 }
7
Returns: 188
{1, 2, 2, 1 }
2
Returns: 3
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }
3
Returns: 26
{1, 2, 3, 4, 5, 6, 7, 7, 65, 5, 4, 23, 2, 3, 2, 3, 2, 1, 2, 3, 2, 55 }
11
Returns: 66
{1, 100, 100, 1, 1, 100 }
2
Returns: 201