Problem 4: Architecture

https://open.kattis.com/problems/architecture

Let xx be the maximum of x1,...,xRx_1,...,x_R(the second line of input), and let yybe the maximum of y1,...,yCy_1,...,y_C (the third line of input).

If x=yx = 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=4x=y=4. Then, we can always use the row and column of xx and yy for the skylines, and fill the rest of the table with 0s:

(0300020014110200)\begin{pmatrix} 0 & 3 & 0 & 0 \\ 0 & 2 & 0 & 0 \\ 1 & 4 & 1 & 1 \\ 0 & 2 & 0 & 0 \end{pmatrix}

If x>yx > y, there must still be an entry in the table with value xx, so that the eastern skyline can have xx in one row. Then, the column with that entry will have to have a skyline of height x\geq x too, but as the maximum northern skyline height yy is less thanxx, this is impossible. Similarly, x<yx<yis also impossible.

So, output possible if x=yx=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

Last updated