Game of Stones
Time limit2sMemory limit512 MB
Two players alternately remove stones from piles, with Petyr taking up to A per turn and Varys up to B. Determine who wins under optimal play.
- Level
Medium6 of 10
- Topics
- Game theory, Math
- Solved
- No attempts yet
Problem
Two players, Petyr and Varys, play a game in which they remove stones from N piles in alternating turns. On his turn, Petyr can remove at most A stones from any one pile. On his turn, Varys can remove at most B stones from any one pile. Each player must remove at least one stone on every turn. The player who removes the last stone wins.
The game has already started, and it is Petyr's turn. Determine whether Petyr can win if both players play optimally.
Input
The first line contains three integers N, A, and B (, ). N is the number of piles, and A and B are the limits for Petyr and Varys. The second line contains N integers X1, ..., XN (), the current number of stones in each pile.
Output
Print the name of the winner, either Petyr or Varys.