Matches problem from May Long challenge

Link to the problem : CodeChef: Practical coding for everyone

I need help in understanding how the players play the moves .

The problem statement mentions that the players play ‘Optimally’ . I did not get a clear Idea from this .

I am asking this because I found cases where a change in one player’s move changes the outcome.


For example , consider the number of matches in heap A = 36 and heap B =10 .

Note here the starting player will have three options to play :
1)Remove 10 from A
2)Remove 20 from A
3)Remove 30 from A

Considering cases (1) and (2) ;
Please notice that both the cases CAN Lead into different outcomes .

I would appreciate if someone could make this clear if I have incorrectly percieved something .

I hope I could convey things effectively . Any suggestions / advices would be appreciated !

Thanks !

A player will choose the outcome with highest winning chance.

In above cases, only case 2 guarantee winning condition for player 1, hence player 1 will choose to remove 20.

Sequence :
36 10
16 10 – P1
6 10 – p2
6 4 – p1
2 4 – p2
2 0 – p1 wins