Robert is designing a new computer game. The game involves one hero,
The hero starts off entering dungeon
- If the hero's strength is greater than or equal to the opponent's strength
, the hero wins. This causes the hero's strength to increase by . In this case the hero enters dungeon next . - Otherwise, the hero loses. This causes the hero's strength to increase by
. In this case the hero enters dungeon next.
Note
The game ends when the hero enters dungeon
Robert asked you to test his game by running
Implementation Details
You should implement the following procedures:
void init(int n, std::vector<int> s, std::vector<int> p, std::vector<int> w, std::vector<int> l)
: number of opponents. , , , : arrays of length . For : is the strength of the opponent . It is also the strength gained by the hero after winning against opponent . is the strength gained by the hero after losing against opponent . is the dungeon the hero enters after winning against opponent . is the dungeon the hero enters after losing against opponent .
- This procedure is called exactly once, before any calls to
simulate
(see below).
long long simulate(int x, int z)
: the dungeon the hero enters first. : the hero's starting strength.- This procedure should return the hero's strength when the game ends, assuming the hero starts the game by entering dungeon
, having strength . - The procedure is called exactly
times.
Examples
Consider the following call:
init(3, {2, 6, 9}, {3, 1, 2}, {2, 2, 3}, {1, 0, 1})

The diagram above illustrates this call. Each square shows a dungeon. For dungeons
Let's say the grader calls simulate(0, 1)
.
The game proceeds as follows:
Dungeon | Hero's strength before confrontation | Result |
---|---|---|
Lose | ||
Lose | ||
Win | ||
Lose | ||
Win | ||
Win | ||
Game ends |
As such, the procedure should return
Let's say the grader calls simulate(2, 3)
.
The game proceeds as follows:
Dungeon | Hero's strength before confrontation | Result |
---|---|---|
Lose | ||
Lose | ||
Win | ||
Lose | ||
Win | ||
Win | ||
Game ends |
As such, the procedure should return
Constraints
(for all ) (for all ) (for all )
Subtasks
- (
points) (for all ) - (
points) (for all ) - (
points) , all opponents have the same strength, in other words, for all . - (
points) , there are at most distinct values among all values of . - (
points) - (
points) No additional constraints.
Sample Grader
The sample grader reads the input in the following format:
- line
: - line
: - line
: - line
: - line
: - line
: for the -th call tosimulate
.
The sample grader prints your answers in the following format:
- line
: the return value of the -th call tosimulate
.
Attachment Package
The sample grader and sample test cases are available here: dungeons.zip.
Comments
edit: sorry it seems that it can't be 2GB for system reasons :(
ML should be 2GB.