Let x be the maximum of x1,...,xR(the second line of input), and let ybe the maximum of y1,...,yC (the third line of input).
If x=y, we can always assign building heights. For example, consider the input:
4 4
3 2 4 2
1 4 1 1
Here, x=y=4. Then, we can always use the row and column of x and y for the skylines, and fill the rest of the table with 0s:
0010324200100010
If x>y, there must still be an entry in the table with value x, so that the eastern skyline can have x in one row. Then, the column with that entry will have to have a skyline of height ≥x too, but as the maximum northern skyline height y is less thanx, this is impossible. Similarly, x<yis also impossible.
So, output possible if x=y, and output impossible otherwise.
C++ has a function max_element() which finds the max number in a vector. Example usage:
vector<int> v ={3, 1, 4, 7, 2};int m =*max_element(v.begin(),v.end());// m will be 7