#P1212. Packing Rectangles

    ID: 14217 Type: Default 1000ms 256MiB

Packing Rectangles

Packing Rectangles

Given four rectangular blocks with dimensions \(a_i\) and \(b_i\) (\(1\le i\le4\)), the task is to determine all possible dimensions of the minimal enclosing rectangle that can contain these four blocks without overlapping. The sides of each small rectangle must be parallel to the sides of the enclosing rectangle.

A valid arrangement is one of the six basic placement schemes (up to rotation and reflection), for example:

  • Case 1: All four rectangles placed in a row. \(W = a_1+a_2+a_3+a_4,\; H = \max\{b_1,b_2,b_3,b_4\}\).
  • Case 2: Three rectangles in one row and the fourth placed below the row. (Taking the fourth block as the single one in the lower row, so that \(W=\max\{a_1+a_2+a_3, a_4\}\) and \(H=\max\{b_1,b_2,b_3\}+b_4\)).
  • Case 3: Two rectangles on the top row and two on the bottom row. For instance, if the top row has blocks 1 and 2 and the bottom row has blocks 3 and 4 then \(W = \max\{a_1+a_2, a_3+a_4\}\) and \(H = \max\{b_1,b_2\} + \max\{b_3,b_4\}\).
  • Case 4: Other L‐shaped and split arrangements. (There are two more distinct arrangements.)

Note that the blocks can be rotated by 90° (i.e. swap \(a_i\) and \(b_i\)) so long as their edges remain parallel to the edges of the enclosing rectangle. There may be several different enclosing rectangles (with different side lengths) that all have the same minimal area. Output all such distinct pairs of side lengths. For each enclosing rectangle, output the smaller dimension first.

Input/Output Format

inputFormat

The input consists of 4 lines. Each line contains two positive integers separated by a space. The two integers represent the dimensions of one rectangular block.

outputFormat

For each possible minimal enclosing rectangle with the smallest area, output a line with two integers: the smaller side and the larger side. Output the pairs in increasing order (first by the smaller side, then by the larger side).

sample

1 1
1 1
1 1
1 1
1 4

2 2

</p>