Tricky Subset Problem
Submissions: 1426   Accuracy:

9.97%

  Difficulty: Medium   Marks: 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. 

 

Input:
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.

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

Constraints:
1<=T<=10
1<=N<=100000
1<=S, Ai, X<= 1018

Example:
Input:
2
1 4 7
1 2 4 2
100 2 500
51 88
Output:
yes
no

Explanation:
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.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Deepayan Bardhan
Author: whiteman


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.