F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

For

Time 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
5 1 8 5 7 6 9 2 8 3 1 10 7 5 7 5 3 1 9 9 1 4 7 4 2 3 9 5 4 5 3 4 0
 

Sample Output
Case 1: 6 9 6 9 -1 -1 6 9 5 7 Case 2: 9 9 9 9 4 5 -1 -1 4 5 9 5 3 4 -1 -1 9 9 4 5
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-08 09:03:44, Gzip enabled