P9028 [COCI 2022/2023 #1] Right Click

Background

NFP means the future. When it comes to finance, Noa’s friends all want to hear him say this.

Description

NFP is a cryptocurrency. The value of one NFP over $s$ days can be represented by an $r$-row, $s$-column character matrix containing only the characters ``.`` and ``#``. In column $i$, the ``#`` in the $j$-th row from bottom to top means that on day $i$ the value of this NFP is $j$. The “insecurity” of an NFP is defined as the difference between the maximum value it reaches and the minimum value it reaches over the $s$ days. ``` ....##. #..#... .##.... ......# ``` As shown above, the values of this NFP over $7$ days are: $3,2,2,3,4,4,1$. Its “insecurity” is $3$. Now Noa wants you to help him determine the insecurity of the $n$ NFPs he has.

Input Format

The first line contains three integers $n, r, s$, representing the number of NFPs, the number of rows of the matrix, and the number of columns. Then follow $n$ matrices of size $r \times s$, describing the values of each NFP over $s$ days. It is guaranteed that in the value matrix of each NFP, every column contains exactly one character ``#``.

Output Format

Output $n$ lines, each being the insecurity of one NFP.

Explanation/Hint

| Subtask | Score | Special Property | | :----------: | :----------: | :----------: | | $1$ | $5$ | $r=s=2$ | | $2$ | $15$ | $n=1$ | | $3$ | $30$ | No special property | For $100\%$ of the testdata, $1 \leq n \leq 20$, $2 \leq r, s \leq 50$. The full score for this problem is $50$ points. Translated by ChatGPT 5