New array

0

0 votes
, Binary search algorithm, Medium, Searching algorithm, Algorithms, Binary Search
Problem

You are given an array a containing N positive integers. You have to create a new array b from the given array.

The elements of the array b can be evaluated by using the equation bj = ji=1ai2ji.

There are Q queries to be answered. In each query, a single integer pi is given and asked if it is possible to get pi by adding some of the elements of the array b. If it is possible, print Yes else print No.

Input format

  • The first line of input contains a single integer N.
  • Next line contains N space-separated integers ai.
  • Next line contains a single integer Q.
  • The last line of input contains Q space-separated integers pi.

Output format

Print Q space-separated strings, where ith string is an answer to the ithquery.

Constraints

  • 1n,ai105
  • 1q103
  • 1pi1010
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Array b for the given input will be {3,8}.

Editor Image

?