|
||||||||||
ForTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1248 Accepted Submission(s): 568 Problem Description LMY is a mathematics lover. Now LMY likes to play matrix. LMY designs such a matrix problem. In a large matrix, there are some elements has been marked. For every marked element, return a marked element whose row and column are larger than the original marked element¡¯s row and column respectively. If there are multiple solutions, return the element whose row is the smallest; and if there are still multiple solutions, return the element whose column is the smallest. If there is no solution, return -1 -1. Of course LMY wants YY also like matrix. So she lets YY develop a program to solve the problem. But YY is very busy now. He should learn English for his enrollment examination for Ph.D. students. Could you help YY develop the program? Input The input consists of multiple test cases. For each test case, the first line contains only one integer n. n ¡Ü 1000. Each of the next n lines describes a marked element¡¯s row and column. A marked element¡¯s row and column can be repeatedly showed. There is a blank line between two consecutive test cases. End of input is indicated by a line containing a zero. Output Start each test case with "Case #:" on a single line, where # is the case number starting from 1. For each element¡¯s row and column, output the result. The format is showed as sample output. There is a blank line between two consecutive test cases. Sample Input
Sample Output
Source | ||||||||||
|