Jumps
Time limit1sMemory limit128 MB
Given piles of pieces on numbered squares, repeatedly apply the jump rules until no two neighbouring squares together hold two or more pieces, then print the occupied squares.
- Level
Medium6 of 10
- Topics
- Greedy, Simulation, Math, Implementation
- Solved
- No attempts yet
Problem
"Jumps" is a board game played on a tape of squares that extends without bound to the left and to the right. Finitely many pieces stand on the squares, and a single square may hold more than one piece. The leftmost non-empty square is numbered 0. Squares to the right are numbered 1, 2, 3, ..., and squares to the left are numbered -1, -2, -3, .... A configuration is described by listing, for every occupied square, the square's number together with the number of pieces on it.
Two kinds of moves change a configuration:
- Jump right: remove one piece from a square and one piece from square , then place one piece on square .
- Jump left: remove one piece from a square , then place one piece on square and one piece on square .
A configuration is final when every pair of neighbouring squares holds at most one piece in total. Starting from any configuration, a finite sequence of moves always leads to exactly one final configuration.
Given the initial configuration, compute the final configuration it reaches.
Input
The first line contains one integer (), the number of non-empty squares in the initial configuration.
Each of the next lines describes one non-empty square with two integers: the square's number and the number of pieces on it. The squares are listed in increasing order of their numbers. Every square number is at most , and every square holds at most pieces.
Output
Print a single line with the numbers of the occupied squares of the final configuration, in increasing order, separated by single spaces.