Easy Sum Set Problem
Practice
3.6 (195 votes)
Algorithms
Easy
Searching
Problem
90% Success 29368 Attempts 10 Points 2s Time Limit 256MB Memory 1024 KB Max Code

In this problem, we define "set" is a collection of distinct numbers. For two sets \(A\) and \(B\), we define their sum set is a set \(S(A, B) = \{a + b | a\in A, b \in B\}\). In other word,  set \(S(A, B)\) contains all elements which can be represented as sum of an element in \(A\) and an element in \(B\). Given two sets \(A, C\), your task is to find set \(B\) of positive integers less than or equals \(100\) with maximum size such that \(S(A, B) = C\). It is guaranteed that there is unique such set.

Input Format

The first line contains \(N\) denoting the number of elements in set \(A\), the following line contains \(N\) space-separated integers \(a_i\) denoting the elements of set \(A\).

The third line contains \(M\) denoting the number of elements in set \(C\), the following line contains \(M\) space-separated integers \(c_i\) denoting the elements of set \(C\).

Output Format

Print all elements of \(B\) in increasing order in a single line, separated by space.

Constraints

  • \(1 \le N, M \le 100\)
  • \(1 \le a_i, c_i \le 100\)

 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:10
6 votes
Tags:
Linear SearchAlgorithmsGreedy algorithm
Points:10
16 votes
Tags:
AlgorithmsBrute ForceImplementationLinear SearchIterators
Points:10
66 votes
Tags:
AlgorithmsBrute ForceC++Searching