Diagonal Numbering
InterviewTime limit1sMemory limit1024 MB
Given an r by c table numbered along upper-right to lower-left diagonals, find the row and column of each of q given cell numbers.
- Level
Medium4 of 10
- Topics
- Math, Implementation, Binary search
- Solved
- No attempts yet
Problem
Number the cells of a rectangular table with rows and columns, starting from the top left corner. Cells are numbered along diagonals that run from the upper right to the lower left. Cells on the same diagonal are numbered from top to bottom.
For example, a table is numbered as follows:
cell numbers are given. For each number, find the cell that contains it.
Input
The first line contains three integers , , and (, ).
The second line contains integers .
Output
Print lines. For each , print two integers: the row and the column of the cell that contains it. Rows are numbered from 1 from top to bottom, and columns are numbered from 1 from left to right.