#K67377. Max Elements in Containers

    ID: 32629 Type: Default 1000ms 256MiB

Max Elements in Containers

Max Elements in Containers

You are given n elements and k containers. Each element has a specific size and each container has a given volume. An element can be placed in a container if and only if its size is less than or equal to the container's volume. Each container can hold at most one element.

Your task is to determine the maximum number of elements that can be placed into the containers. A common strategy is to sort both the list of element sizes and the list of container volumes, and then use a two-pointer technique to match elements to containers.

For analysis, note that an element at index \(i\) can be placed in container at index \(j\) if \(\text{sizes}[i] \leq \text{volumes}[j]\). Formally, we wish to maximize the number \(x\) such that:

$$x = \max\{ i \mid \text{sizes}[i] \leq \text{volumes}[j] \text{ for some } j \}$$

inputFormat

The input is provided via standard input (stdin) in the following format:

  • The first line contains two integers n and k, representing the number of elements and the number of containers, respectively.
  • The second line contains n space-separated integers, representing the sizes of the elements.
  • The third line contains k space-separated integers, representing the volumes of the containers.

outputFormat

Output a single integer representing the maximum number of elements that can be placed into the containers. The output should be written to standard output (stdout).

## sample
5 3
2 3 4 5 6
5 10 5
3