#P8874. [传智杯 #5 初赛] F-二人的大富翁游戏
[传智杯 #5 初赛] F-二人的大富翁游戏
Background
As college students, Renko and Merry have more free time after class than they did in high school. When they have no classes, they like to play Monopoly and share their joys and sorrows during the game.

As shown in the figure, this is a Monopoly map with . Players move on the circular tiles, while buildings can be constructed on the square tiles. Each circular tile corresponds to exactly one square tile.
(Friendly reminder: gambling is wrong.)
Problem Description
Renko and Merry are playing a Monopoly game. This Monopoly game is customized by Chuanzhi Podcast, and it is slightly different from the usual Monopoly rules, so it is also called Chuanzhi Monopoly.
The Monopoly game consists of tiles, numbered counterclockwise as , forming a ring. Renko and Merry both start on tile . At the beginning, both Renko and Merry have dollars. In each round, Renko rolls the dice first, then Merry rolls the dice. When a player takes an action, let the number on the top face of the die be ; then the player moves steps counterclockwise. During the movement, for every tile the player passes through, there are two cases:
- If the current tile (suppose it is numbered ) has a building and the building belongs to the moving player, then the moving player can gain an additional dollars.
- If the current tile has a building but it belongs to the other player, then the moving player must transfer dollars to the other player.
After the movement ends, there are also two cases:
- If the current tile (let it be numbered ) has no building, then the moving player may choose to pay dollars (only if the player's current money is at least ) to build a building, and then is initialized to .
- If the building on the current tile belongs to the moving player, and suppose it is a level building, then the moving player may choose to spend dollars to upgrade the building, with the effect . Here, is the cost to upgrade the level building on tile to a level building. Multiple upgrades can be performed within the same turn. In particular, the maximum building level is . If the current building level has already reached the maximum, it cannot be upgraded.
- After all building operations are finished, the control is transferred to the other player.
After both players complete one full round, every building on the ring provides money to its owner. Specifically, the building on tile provides its owner with money. The game ends if and only if there exists a player whose money becomes negative during their action or at the end of their action. That player becomes the loser (in other words, having money during the process is allowed).
Given the operations in each of the rounds for Renko and Merry, determine who will be the loser.
Input Format
The first line contains four positive integers , representing the number of tiles, the initial money, the number of rounds, and the maximum building level.
Starting from the second line, the next lines each contain positive integers, representing , where ranges from to .
Line contains positive integers representing .
Starting from line , there are several lines, and each line is one of the following two types:
- , meaning the current player rolled the dice and the top face is . Then the player moves steps counterclockwise.
- , meaning the current player performs building or upgrading a total of times at the current position.
- During this process, if the current position already has the opponent's building, then this operation is ignored.
- If there is not enough money to upgrade times, then only upgrade to the highest level allowed by the available money.
- During this process, if performing the next upgrade would make the building level exceed , then all subsequent upgrades are ignored.
In particular, except for the first time, each time an operation appears, it means the player switches. That is, when the first operation appears, the acting player is Renko; the second time it is Merry; the third time it is Renko; and so on. Note that an operation does not switch the acting player.
In addition, it is guaranteed that after each operation, there is at most operation following it.
Output Format
If the winner and loser have already been determined, output the loser (output if Renko loses; output if Merry loses).
If no winner is determined, output their current money in the order: Renko first, then Merry.
6 40 5 3
10 20 30
15 25 35
6 8 12
6 12 18
8 16 24
8 12 40
1 2 3 4 5 6
1 4
2 3
1 2
2 5
1 3
1 2
2 1
1 5
2 3
1 3
2 4
1 4
1 6
2 2
1 3
2 1
1 3
2 1
Merry
6 9961 5 3
10 20 30
15 25 35
6 8 12
6 12 18
8 16 24
8 12 40
1 2 3 4 5 6
1 4
2 3
1 2
2 5
1 3
1 2
2 1
1 5
2 3
1 3
2 4
1 4
1 6
2 2
1 3
2 1
1 3
2 1
10099 9946
Hint
[Sample Explanation 1]
In the first round, Renko first moves steps and arrives at tile , and then tries to build and upgrade the building on tile a total of times. However, , so she can only build it up to level . At this time, Renko has dollars left.
Next, Merry moves steps and arrives at tile , and then tries to build and upgrade the building on tile a total of times. Since , and upgrading five times would exceed the maximum level , she can only perform upgrades, and at this time Merry has dollars left.
After the round ends, each building provides its owner with money. That is, Renko now has dollars, and Merry has dollars.
In the second round, Renko first moves steps and arrives at tile . Then Merry moves steps and arrives at tile , and pays/collects money. Since , Merry's money becomes negative, so output .
[Sample Explanation 2]
Only the initial money differs slightly from the first sample, so no winner can be determined within these rounds. Therefore, output the current money of the two players.
[Constraints]
For all data, it is guaranteed that , , , (you do not need to care how to get a die with faces). The data guarantees that the number of operation is exactly .
Translated by ChatGPT 5