#K80542. Packing Boxes into Crates

    ID: 35553 Type: Default 1000ms 256MiB

Packing Boxes into Crates

Packing Boxes into Crates

You are given M boxes and N crates. Each box and crate is defined by its width and height. A box can be packed into a crate if and only if both its width and height are less than or equal to the corresponding dimensions of the crate. Each crate can hold at most one box.

Your task is to determine the maximum number of boxes that can be packed into the crates. Boxes are processed in the order they are given. For each box, if there is a crate in which it fits, pack the box into the first such available crate.

The condition for a box with dimensions \(w, h\) to fit in a crate with dimensions \(W, H\) is given by the inequalities:

\(w \leq W\) and \(h \leq H\).

inputFormat

The input is read from standard input and has the following format:

  1. The first line contains two integers \(M\) and \(N\), the number of boxes and the number of crates, respectively.
  2. The next \(M\) lines each contain two integers representing the width and height of a box.
  3. The following \(N\) lines each contain two integers representing the width and height of a crate.

outputFormat

Output a single integer to standard output: the maximum number of boxes that can be packed into the crates.

## sample
4 3
4 5
6 8
7 3
5 5
8 6
5 6
4 4
2