#C10222. Intersection of Two Arrays

    ID: 39404 Type: Default 1000ms 256MiB

Intersection of Two Arrays

Intersection of Two Arrays

Given two arrays of integers, possibly containing duplicates, determine their intersection such that the result contains only unique common elements. The resulting intersection must be output in ascending order.

Input is provided as follows:

  • The first line contains two integers \(n\) and \(m\), representing the sizes of the two arrays.
  • The second line contains \(n\) integers, which are the elements of the first array.
  • The third line contains \(m\) integers, which are the elements of the second array.

If there are no common elements, output an empty line.

inputFormat

The input consists of three lines:

  1. The first line contains two integers \(n\) and \(m\) separated by a space.
  2. The second line contains \(n\) space-separated integers representing the first array.
  3. The third line contains \(m\) space-separated integers representing the second array.

outputFormat

Output the unique common elements found in both arrays, sorted in ascending order, separated by a single space. If no common elements exist, output an empty line.

## sample
4 2
1 2 2 1
2 2
2

</p>