#B3909. Painting Operation Analysis

    ID: 11566 Type: Default 1000ms 256MiB

Painting Operation Analysis

Painting Operation Analysis

Given an \( n \times m \) matrix \( a \) where each row represents a region of an artwork and each column represents a painting operation, the element \( a_{i,j} \) indicates the intensity of the paint applied in the \( j\text{-th} \) painting operation on region \( i \). If \( a_{i,j} = 0 \), it means that region \( i \) was not painted in the \( j\text{-th} \) operation.

For each region, you are required to find the painting operation with the maximum paint intensity. Let this occur at operation \( k \). Then, count how many painting operations before \( k \) (i.e. for all \( j < k \)) have a non-zero intensity strictly less than \( a_{i,k} \). It is guaranteed that for each region, the maximum painted intensity is unique.

Note: Operations with \( a_{i,j} = 0 \) (i.e. not painted) should be ignored when counting.

inputFormat

The first line contains two integers \( n \) and \( m \) (number of regions and number of painting operations respectively).

Then follow \( n \) lines, each containing \( m \) integers \( a_{i,1}, a_{i,2}, \ldots, a_{i,m} \) representing the paint intensities for the \( i\text{-th} \) region.

outputFormat

For each of the \( n \) regions, output two integers separated by a space on a new line: the index (1-indexed) of the painting operation that has the maximum intensity, and the count of painting operations before that with a positive intensity strictly less than the maximum intensity.

sample

1 5
0 3 2 5 4
4 2

</p>