#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 n=10n=10. 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 nn tiles, numbered counterclockwise as 1,2,,n1,2,\dots,n, forming a ring. Renko and Merry both start on tile 11. At the beginning, both Renko and Merry have mm 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 kk; then the player moves kk steps counterclockwise. During the movement, for every tile the player passes through, there are two cases:

  • If the current tile (suppose it is numbered ii) has a building and the building belongs to the moving player, then the moving player can gain an additional aia_i dollars.
  • If the current tile has a building but it belongs to the other player, then the moving player must transfer aia_i dollars to the other player.

After the movement ends, there are also two cases:

  • If the current tile (let it be numbered ii) has no building, then the moving player may choose to pay Ci,0C_{i,0} dollars (only if the player's current money is at least Ci,0C_{i,0}) to build a building, and then aia_i is initialized to Ci,0C_{i,0}.
  • If the building on the current tile belongs to the moving player, and suppose it is a level jj building, then the moving player may choose to spend Ci,jC_{i,j} dollars to upgrade the building, with the effect aiai+Ci,ja_i \gets a_i+C_{i,j}. Here, Ci,jC_{i,j} is the cost to upgrade the level jj building on tile ii to a level j+1j+1 building. Multiple upgrades can be performed within the same turn. In particular, the maximum building level is LL. 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 ii provides its owner with did_i 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 00 money during the process is allowed).

Given the operations in each of the qq rounds for Renko and Merry, determine who will be the loser.

Input Format

The first line contains four positive integers n,m,q,Ln,m,q,L, representing the number of tiles, the initial money, the number of rounds, and the maximum building level.

Starting from the second line, the next nn lines each contain LL positive integers, representing Ci,jC_{i,j}, where jj ranges from 00 to L1L-1.

Line (n+2)(n+2) contains nn positive integers representing did_i.

Starting from line (n+3)(n+3), there are several lines, and each line is one of the following two types:

  • 1 k\texttt{1 k}, meaning the current player rolled the dice and the top face is kk. Then the player moves kk steps counterclockwise.
  • 2 k\texttt{2 k}, meaning the current player performs building or upgrading a total of kk 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 kk 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 LL, then all subsequent upgrades are ignored.

In particular, except for the first time, each time an operation 1\bm 1 appears, it means the player switches. That is, when the first 1 k\texttt{1 k} 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 2 k\texttt{2 k} does not switch the acting player.

In addition, it is guaranteed that after each 1\bm 1 operation, there is at most 1\bm 1 2\bm 2 operation following it.

Output Format

If the winner and loser have already been determined, output the loser (output Renko\texttt{Renko} if Renko loses; output Merry\texttt{Merry} 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 44 steps and arrives at tile 55, and then tries to build and upgrade the building on tile 55 a total of 33 times. However, C5,0+C5,1+C5,2=48C_{5,0}+C_{5,1}+C_{5,2}=48, so she can only build it up to level 22. At this time, Renko has 1616 dollars left.
Next, Merry moves 22 steps and arrives at tile 33, and then tries to build and upgrade the building on tile 33 a total of 55 times. Since C3,0+C3,1+C3,2=26C_{3,0}+C_{3,1}+C_{3,2}=26, and upgrading five times would exceed the maximum level LL, she can only perform 33 upgrades, and at this time Merry has 1414 dollars left.
After the round ends, each building provides its owner with did_i money. That is, Renko now has 2121 dollars, and Merry has 1717 dollars.
In the second round, Renko first moves 33 steps and arrives at tile 22. Then Merry moves 22 steps and arrives at tile 55, and pays/collects aia_i money. Since ai=24a_i=24, Merry's money becomes negative, so output Merry\texttt{Merry}.

[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 1n,L1001 \leq n,L\leq 100, 1q1041 \leq q \leq 10^4, 1m,Ci,j,di1061 \leq m,C_{i,j},d_i \leq 10^6, 1k1031 \leq k \leq 10^3 (you do not need to care how to get a die with kk faces). The data guarantees that the number of operation 11 is exactly 2×q2\times q.

Translated by ChatGPT 5