#K45297. Intersection of K Sorted Arrays
Intersection of K Sorted Arrays
Intersection of K Sorted Arrays
You are given k sorted arrays. Your task is to find the common elements (intersection) that appear in every array. An element is considered common if it appears at least once in each array. If no element is common to all arrays, output an empty line.
In mathematical terms, let \(A_1, A_2, \ldots, A_k\) be the sorted arrays. An integer \(x\) is in the intersection if: \[ \text{count}(x)=k \] where \(\text{count}(x)\) is the number of arrays in which \(x\) appears at least once.
The answer should list the common elements in ascending order.
inputFormat
The input is read from standard input and has the following format:
- The first line contains an integer k, the number of arrays.
- Each of the next k lines begins with an integer n (the number of elements in that array), followed by n sorted integers separated by spaces.
outputFormat
Output to standard output the common elements present in all arrays in ascending order, separated by a single space. If there are no common elements, output an empty line.
## sample3
5 1 2 3 4 5
4 2 3 5 7
6 2 3 4 5 9 10
2 3 5