Rank and File (Small)
Time limit5sMemory limit512 MB
Given all but one of the rows and columns of a valid grid, find the missing list of N heights in increasing order.
- Level
Medium4 of 10
- Topics
- Hash map, Implementation
- Solved
- No attempts yet
Problem
When Sergeant Argus's army assembles for drilling, the soldiers stand in the shape of an square grid, with exactly one soldier in each cell. Each soldier has a certain height.
Argus believes that he must keep an eye on all of his soldiers at all times. Since he likes to look at the grid from the upper left, he requires that:
- Within every row of the grid, the soldiers' heights are in strictly increasing order from left to right.
- Within every column of the grid, the soldiers' heights are in strictly increasing order from top to bottom.
No two soldiers in the same row or column may have the same height, but multiple soldiers in the grid may have the same height.
Since soldiers sometimes train separately with their row or their column, Argus has asked you to make a report consisting of lists of the soldiers' heights: one for each row (in left-to-right order) and one for each column (in top-to-bottom order). While surveying the soldiers you only had small pieces of paper to write on, so you wrote each list on a separate piece of paper. On your way back to your office, a loud bugle blast startled you and you dropped all of the pieces of paper, and the wind blew one away before you could recover it. The other pieces of paper are now in no particular order, and you do not remember which lists are rows and which are columns, since you did not write that down.
Argus will make you do hundreds of push-ups if you give him an incomplete report. Find the missing list.
Input
The first line of the input gives the number of test cases, . test cases follow. Each consists of one line with an integer , followed by lines of integers each, representing the lists you have, as described in the statement. These lists are guaranteed to be all but one of the rows and columns of a valid grid, as described in the statement.
Limits
- every height
- The integers on each line are in strictly increasing order.
Output
For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is a list of integers in strictly increasing order, separated by spaces, representing the missing list.
Hint
In the sample case, the arrangement must be either this:
1 2 3
2 3 4
3 5 6
or this:
1 2 3
2 3 5
3 4 6
In either case, the missing list is 3 4 6.