Пожалуйста, подпишитесь на официальный канал Codeforces в Telegram по ссылке https://t.me/codeforces_official. ×

Блог пользователя profesir

Автор profesir, история, 4 года назад, По-английски

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?

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

»
4 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

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.