#C2459. Reconcile Arrays Problem
Reconcile Arrays Problem
Reconcile Arrays Problem
Given two lists of positive integers, the task is to find the elements that are missing in one list compared to the other. Specifically, you need to compute two lists:
- The list of elements that are present in the second list but not in the first list.
- The list of elements that are present in the first list but not in the second list.
Both lists must be sorted in ascending order. If a particular list has no missing elements, output -1
for that list.
This can be mathematically expressed as follows, using set difference:
\[ Missing1 = \text{sorted}(B \setminus A),\quad Missing2 = \text{sorted}(A \setminus B)\]If either Missing1 or Missing2 is empty, output -1
for that list instead.
inputFormat
The input is read from standard input (stdin) and consists of four lines:
- An integer
n
representing the number of elements in the first list. n
space-separated positive integers that form the first list.- An integer
m
representing the number of elements in the second list. m
space-separated positive integers that form the second list.
Note: If n
or m
is 0, the corresponding list is empty.
outputFormat
The output should be written to standard output (stdout) in two lines:
- The first line contains the sorted missing elements from the first list's perspective (i.e. the elements that are in the second list but not in the first list). If there are no such elements, output
-1
. - The second line contains the sorted missing elements from the second list's perspective (i.e. the elements that are in the first list but not in the second list). If there are no such elements, output
-1
.
5
2 4 6 8 10
7
1 2 3 4 5 6 7
1 3 5 7
8 10
</p>