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 int[] skills, representing the skills of all players. Also you will be given an int teams - the number of teams which must be created. You are to simulate the draft process and return the maximal team strength among all the teams. The strength of a team is the sum of the skills of all its players.
|