Computer Science, asked by knightchess, 7 months ago

5. You are given an array A of size N, and Q queries to deal with. For each query, you are
given an integer X, and you're supposed to find out if X is present in the array A or not.
Input:
The first line contains two integers, N and Q, denoting the size of array A and number of
queries. The second line contains N space separated integers, denoting the array of
elements Ai. The next Q lines contain a single integer X per line.
Output:
For each query, print YES if the X is in the array, otherwise print NO.
Constraints:
1 <=N, Q <= 105
1 <= Ai <= 10°
1 <= x <= 10°

Answers

Answered by sharifasharifa819
5

Answer:

Write a program that, given an array A[] of n numbers and another number x, determines whether or not there exist two elements in S whose sum is exactly x.

Examples:

Input: arr[] = {0, -1, 2, -3, 1}

sum = -2

Output: -3, 1

If we calculate the sum of the output,

1 + (-3) = -2

Input: arr[] = {1, -2, 1, 0, 5}

sum = 0

Output: -1

No valid pair exists.

Similar questions