Tricky Subset Problem
Medium Accuracy: 8.96% Submissions: 1805 Points: 4

N children are made to stand in a queue, where everyone is given a number Ai. Then the teacher writes a number S on a page and passes it to the first person. The first person adds all the numbers written on the paper ( for now only S is there ) and adds his number Ato it and writes on the paper and passes to the second one. The second one does the same i.e. adds all the numbers on the paper ( S & (S+Ai) ) and adds his own number and passes it to next, and the process continues.
Given this series of numbers you have to determine whether a number X can be formed by adding some of the numbers from the given series or not. 


The first line contains T, denoting the number of test cases. Then T test cases follow. Each test case has two lines. The first line of each test case has three numbers S, N and X. The second line consists of N numbers denoting the elements of the array A.

For each test case in a new line print "yes" if X can be formed using the numbers in the series else print "no".

1<=S, Ai, X<= 1018

1 4 7
1 2 4 2
100 2 500
51 88

In the first example, the sequence of numbers are 1, 2, 5, 12, 22. Using 2 & 5 we can form 7.
In the second example, the sequence of numbers are 100, 151 & 339. So, using these numbers we cannot form 500.

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.