Question Description:
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 a 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.
Constraints:
1 ≤ N, M ≤ 100
1 ≤ ai, ci ≤ 100
Input Formats:
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.
#include<stdio.h>
int main()
{
int N,M;
int A[105],C[105];
int mark[205]={0};
scanf("%d",&N);
for(int i=0;i<N;i++)
scanf("%d",&A[i]);
scanf("%d",&M);
for(int i=0;i<M;i++)
{
scanf("%d",&C[i]);
mark[C[i]]=1;
}
for(int b=1;b<=100;b++)
{
int ok=1;
for(int i=0;i<N;i++)
{
if(!mark[A[i]+b])
{
ok=0;
break;
}
}
if(ok)
printf("%d ",b);
}
return 0;
}
0 Comments