3

There are T1 and T2 Teams playing a game.Both Team have N players.The power of T1 team player are represented in an array and Similarly T2 team player.

The rule of Game are follows:

1.There are only N fights.

2.No player of any team can play twice

3.For each fight score generated from (P1 + P2)%N P1 represent power of T1 .Similarly P2

T2 is aware of the order of T1 is sending their player to play the game T2 wants to obtains minimum score in each fight.

Your task is to determine the order in Which T2 is sending player such that they obtain minimum score for each fight

You are required to print score for each round and the other players of T2.

N=3
T1=[1,2,3]
T2=[2,0,1]
Output:[0,0,0]

N=4
T1=[0,1,2,1]
T2=[3,2,1,1]
output:[1,0,0,2]

Explanation Case 1 N=3: [(1+2)%3,(2+1)%3,(3+0)%3]

What is optimal solution for this problem?

One approach is checking one by one power with T1.

go_k
  • 105
  • 10

1 Answers1

0

This isn't a complete answer, but here's how I would think about it. Having more interesting examples could help develop the idea.

Sort the arrays, one descending, one ascending:

N=4
T1=[0,1,2,1]
T2=[3,2,1,1]

0 1 1 2
3 2 1 1

Now use a pointer to "shift" the alignment while maintaining a variable for the current, ascending target remainder.

Target remainder 0
0 1 1 2
3 2 1 1
^
useless, shift pointer right
  
0 1 1 2
  3 2 1 1
    ^
    useless, shift pointer right
    
0 1 1 2
  3   2 1 1
גלעד ברקן
  • 23,602
  • 3
  • 25
  • 61