#K8976. Shipping Container Packing

    ID: 37602 Type: Default 1000ms 256MiB

Shipping Container Packing

Shipping Container Packing

You are given a shipping container with dimensions \(C_l \times C_w\) and \(n\) rectangular products. Each product is specified by its dimensions \(P_l\) and \(P_w\). Products can be rotated by 90° if necessary. Your task is to determine whether it is possible to pack all products inside the container without overlapping, while ensuring each product is entirely within the container boundaries.

Note: Products may not overlap and must lie completely within \(C_l \times C_w\). The problem requires checking all possible placements and rotations, which may be solved via backtracking.

inputFormat

The input is read from stdin and consists of:

  • The first line contains two integers \(C_l\) and \(C_w\) representing the dimensions of the container.
  • The second line contains an integer \(n\), the number of products.
  • Each of the next \(n\) lines contains two integers \(P_l\) and \(P_w\) representing the dimensions of a product.

outputFormat

Output a single line to stdout containing YES if it is possible to pack all the products into the container without overlapping; otherwise, output NO.

## sample
10 10
3
4 6
5 5
3 3
YES

</p>