Help needed on the problem -> Monsters Battle | CodeChef

@tmwilliamlin sir, you have discussed the solution of the MONSTBAT problem in February Lunchtime 2020 Division 2. But unfortunately there is no explanation of the output of given test case. I am facing a hard time to understand how the output is coming in the given test case . Because according to me the output should have been 60.

Please help me out. Also any other fellow coder who has solved the problem,please help me in understanding the output of the given test case.

Thanks in advance to all.

Say they weren’t allowed to give up. How would the game go.
A\begin{bmatrix} 4 & 5 & 60 \end{bmatrix} A\begin{bmatrix}15 & 16 \end{bmatrix}
D\begin{bmatrix} & & & & \end{bmatrix} D\begin{bmatrix}2\end{bmatrix}
Player 1 score:36
player 2 score:-36
Now Player 1 attacks the highest valued defender with the lowest valued attacker
A\begin{bmatrix} 5 & 60 \end{bmatrix} A\begin{bmatrix}15 & 16 \end{bmatrix}
D\begin{bmatrix} 4 & & \end{bmatrix}D\begin{bmatrix} & & &\end{bmatrix}
Player 1 score: 38
Player 2 score: -38
Now player 2 will attack the highest valued defense card of player 1 with his lowest valued attack card.
A\begin{bmatrix} 5 & 60 \end{bmatrix} A\begin{bmatrix}16 \end{bmatrix}
D\begin{bmatrix}& & \end{bmatrix}D\begin{bmatrix} 15\end{bmatrix}
Player 1 score:34
Player 2 score: -34
And so on player 1 attacks
A\begin{bmatrix} 60 \end{bmatrix} A\begin{bmatrix}16 \end{bmatrix}
D\begin{bmatrix}5 \end{bmatrix}\ \ D\begin{bmatrix} &\end{bmatrix}
Player 1 score:49
Player 2 score:-49
Player 2 attacks
A\begin{bmatrix} 60 \end{bmatrix} A\begin{bmatrix}& \end{bmatrix}
D\begin{bmatrix}& \end{bmatrix}D\begin{bmatrix} 16\end{bmatrix}
player 1 score:44
Player 2 score:-44
player 1 attacks
A\begin{bmatrix} & \end{bmatrix} A\begin{bmatrix} \end{bmatrix}
D\begin{bmatrix}60 \end{bmatrix}D\begin{bmatrix} \end{bmatrix}
Player 1 score:60
Player 2 score:-60
So the turns are
Player 1: 36, 38, 34, 49, 44, 60
Player 2: -36 -38 -34 -49 -44 -60
So let’s analyse the turns.
Will player 1 play on the second last turn: Yes.
Will player 2 play on the third last turn: No, because then player 1 will make him go to -60 from -49
Will player 1 play on the fourth last turn: Yes, because player 2 will give up and he will get 49 points instead of 34.
Will player 2 play on the 5th last turn(2nd turn): No because player 1 will make him go to -49 from -38.
Will player 1 play on the first turn: Yes, because player 2 will give up, and he will get 38 points instead of 36.
So player 1 will play, and then player 2 will give up.

1 Like

@everule1 thank you very much for your speedy response and for your patience to answer my query. This is the explanation I wanted. Thank you for such well written explanation.

1 Like

@everule1 another test case to clear doubt
P1 - (25,26)–>Attack (27,21)–>defense
P2 - (21,27)–> Attack (25,26)–>defense

Will the output be 0? Please confirm. Thanks in advance…

Yes. If you just wanted to check that, just put it in any AC code and check.