Since, to win, any player needs more or equal scores than the other player, considering the other player will always play optimally, at every stage of the game we should find out the maximum difference current player can have over the other player. If the difference is non-negative, that player will surely win no matter what. Otherwise, if the other player plays optimally, the other player will win.
Suppose, at some turn some player sees that item is up for sale and there are at most skips left. She can either skip this turn or purchase the item. Let be the maximum difference of her score over other player’s score. We want to follow the move which maximizes .
Purchase: If we purchase we get .
Skip: If , we get .
For convenience, we can assume .
Of course, if , the player have to purchase the current item. Otherwise, if , she may skip this turn.
Shapla should go first if , second otherwise.