#P15666. [ICPC 2025 Jakarta R] Down Right Chips

[ICPC 2025 Jakarta R] Down Right Chips

题目描述

You have a board of size N×MN \times M, with rows numbered from 11 to NN from top to bottom, and columns numbered from 11 to MM from left to right. Initially, there are Ai,jA_{i,j} chips on the tile at the ii-th row and jj-th column.

You will play a solitaire game on this board. In one move, you can do one of the following.

  • Choose a tile not in the bottommost row with at least two chips on it. Discard one chip from the tile, and move another chip to the tile directly below it.
  • Choose a tile not in the rightmost column with at least one chip on it. Move one chip from the tile to the tile directly to its right.

The game ends when there are no more moves you can make.

There will be QQ changes to the board, and each of the changes will add\textbf{add} WW chips to the tile at the XX-th row and YY-th column. After each change, calculate the minimum number of moves to end the game using the current board.

输入格式

The first line contains three integers NN, MM, and QQ (1N51 \leq N \leq 5; 1M,Q100  0001 \leq M, Q \leq 100\;000).

The next NN lines, each containing MM integers, represent Ai,jA_{i,j} (0Ai,j100  0000 \leq A_{i,j} \leq 100\;000).

Each of the next QQ lines contains three integers XX, YY, and WW (1XN1 \leq X \leq N; 1YM1 \leq Y \leq M; 1W10  0001 \leq W \leq 10\;000) representing a change to the board.

输出格式

Output QQ lines, each containing a single integer representing the minimum number of moves to end the game after each change.

2 3 2
0 2 1
0 1 1
1 2 1
2 3 5
5
5

提示

Explanation of Sample 1:\textit{Explanation of Sample 1:} After the first change, you can play as follows for the minimum number of moves.

  • Move right\textit{right} on tile (1,2)(1, 2).
  • Move down\textit{down} on tile (1,2)(1, 2).
  • Move right\textit{right} on tile (2,2)(2, 2).
  • Move right\textit{right} on tile (2,2)(2, 2).
  • Move down\textit{down} on tile (1,3)(1, 3).