CYCLE CONCEPT

can anyone explain the cycle concept for this(http://www.codechef.com/problems/TMSLT) question?
or any link for the same?

After applying counting sort, consider all players of a particular strength i, that are n in number.

Every alternate player from that group will go to alternate teams.

Hence, if n is even, the net difference in strength of either team will not change as equal number of players will go to both teams.

However, if n is odd, the net difference in strength will be equal to i, that is due to 1 player. That player will go either to Team 1 or Team 2, depending on the number of players chosen before that player.

1 Like