Set Difference
InterviewTime limit2sMemory limit256 MB
Given two sets of up to 500,000 natural numbers each, output the count and sorted list of elements present in A but not in B.
Problem
You are given two sets A and B of natural numbers. Write a program that finds every element that belongs to A but not to B.
Input
The first line contains the number of elements of A, n(A), and the number of elements of B, n(B), separated by a space (1 ≤ n(A), n(B) ≤ 500,000). The second line lists the elements of A and the third line lists the elements of B, separated by spaces. Each element is a natural number no greater than 2,147,483,647, and the elements within a single set are distinct.
Output
On the first line, print the number of elements that belong to A but not to B. On the second line, print those elements in increasing order, separated by spaces. If there is no such element, print only 0 on the first line.