#K68867. Maximum Coins Collection Challenge

    ID: 32960 Type: Default 1000ms 256MiB

Maximum Coins Collection Challenge

Maximum Coins Collection Challenge

You are given a rectangular grid with \(R\) rows and \(C\) columns. Some cells in the grid contain a coin. A robot starts at the top-left corner (cell \((1,1)\)) and wants to reach the bottom-right corner (cell \((R,C)\)); it can only move either right or down.

When the robot moves onto a cell that contains a coin, it collects the coin. The objective is to determine the maximum number of coins that the robot can collect along its journey. Note that cells containing coins contribute \(1\) to the count and no coin is counted more than once.

Input Format: Multiple test cases. For each test case, the first line contains two integers, \(R\) and \(C\). The next line contains a single integer \(N\) indicating the number of cells that contain a coin, followed by \(N\) lines each containing two integers representing the row and column indices of a cell with a coin.

Note: The robot always starts at \((1,1)\) and ends at \((R,C)\). It is assumed that if a coin is present at \((1,1)\) or \((R,C)\), it is counted accordingly.

inputFormat

The input begins with an integer \(T\) representing the number of test cases. For each test case:

  1. The first line contains two integers \(R\) and \(C\) separated by a space.
  2. The second line contains an integer \(N\), the number of coin positions.
  3. The next \(N\) lines each contain two integers \(r\) and \(c\) indicating that there is a coin at row \(r\) and column \(c\).

All input values are read from standard input (stdin).

outputFormat

For each test case, output a single integer on a new line representing the maximum number of coins the robot can collect from the top-left to the bottom-right corner. The output is written to standard output (stdout).

## sample
1
3 3
2
2 2
3 3
2

</p>