#C5415. Minimum Number of Shipping Containers

    ID: 49062 Type: Default 1000ms 256MiB

Minimum Number of Shipping Containers

Minimum Number of Shipping Containers

Given a set of shipping containers and a collection of items, determine the minimum number of containers required to ship all the items.

Each container has three dimensions (width, height, depth) and a weight capacity. Similarly, each item is characterized by its dimensions and weight. An item can be placed in a container if and only if:

  • The width, height, and depth of the item are each less than or equal to those of the container.
  • The sum of the weights of all items placed in the container does not exceed the container's weight capacity.

The volume of an object is given by the formula: \(V = w \times h \times d\).

If it is impossible to ship all items using the available containers, output \(-1\).

inputFormat

The input is read from standard input (stdin) and is formatted as follows:

n m
// Next n lines: container information
w₁ h₁ d₁ capacity₁
w₂ h₂ d₂ capacity₂
... (n lines in total)
// Next m lines: item information
w₁ h₁ d₁ weight₁
w₂ h₂ d₂ weight₂
... (m lines in total)

Here, n is the number of containers and m is the number of items.

outputFormat

Output a single integer to standard output (stdout) representing the minimum number of containers required to ship all the items. If it is not possible to ship all the items using the available containers, output -1.

## sample
2 4
2 2 2 50
3 2 2 75
1 1 1 10
2 1 1 20
1 2 1 25
3 2 1 50
2