Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

profesir's blog

By profesir, history, 4 years ago, In English

Quetion link- Easy Sum Set Problem — https://www.hackerearth.com/practice/algorithms/searching/linear-search/practice-problems/algorithm/easy-sum-set-problem-7e6841ca/description

Solution for Best Submission — https://www.hackerearth.com/submission/45205049

For this test case:-
2
1 2
3
3 4 8

Output as by best submission code — 2

Real Answer should be — 2 6 or 2 7

Can anyone please help me with the real solution?

  • Vote: I like it
  • +2
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

For the input given by you, the answer cannot be 2 6 because then 7 should belong to set C(1 belongs to A and 6 belongs to B). Similarly, 2 7 cannot be the answer. In fact, the input is wrong. In the problem they have guaranteed the existence of a set B such that A+B=C. But I don't think a set B exists for the input given by you. It is quite easy to solve the problem. For each number i from 1 to 100, check if it can occur in set B. The number i can occur in set B if and only if for each element a in A, a+i belongs to C.