-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy patheasy sum set problem
More file actions
58 lines (45 loc) · 1.41 KB
/
easy sum set problem
File metadata and controls
58 lines (45 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
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∈A,b∈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 ai 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 ci 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≤N,M≤100
1≤ai,ci≤100
SAMPLE INPUT
2
1 2
3
3 4 5
SAMPLE OUTPUT
2 3
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
cin>>n; int a[n]; for(int i=0;i<n;i++) cin>>a[i];
cin>>m; int c[m]; for(int i=0;i<m;i++) cin>>c[i];
int b[101]={0};
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(c[j]>a[i]) b[c[j]-a[i]]++;
}
}
int k=1;
while(k<=100)
{
if(b[k] == n) cout<<k<<" ";
k++;
}
}