Devu has an array A consisting of N positive integers. He would like to perform following operation on array.

- Pick some two elements a, b in the array (a could be same as b, but their corresponding indices in the array should not be same).
Remove both the elements a and b and instead add a number x such that x lies between min(a, b) and max(a, b), both inclusive, (i.e. min(a, b) ≤ x ≤ max(a, b)).

Now, as you know after applying the above operation N - 1 times, Devu will end up with a single number in the array. He is wondering whether it is possible to do the operations in such a way that he ends up a number t. 

He asks your help in answering Q such queries, each of them will contain an integer t and you have to tell whether it is possible to end up t. 

-----Input-----
There is only one test case per test file.
First line of the input contains two space separated integers N, Q denoting number of elements in A and number of queries for which Devu asks your help, respectively
Second line contains N space separated integers denoting the content of array A.

Each of the next Q lines, will contain a single integer t corresponding to the query.

-----Output-----
Output Q lines, each containing "Yes" or "No" (both without quotes) corresponding to the answer of corresponding query.

-----Constraints-----
- 1 ≤ N, Q ≤ 105
- 0 ≤ t ≤ 109

-----Subtasks-----
Subtask #1 : 30 points
- 1 ≤ Ai ≤ 2

Subtask #2 : 70 points
- 1 ≤ Ai ≤ 109

-----Example-----
Input 1:
1 2
1
1
2

Output:
Yes
No

Input 2:
2 4
1 3
1
2
3
4

Output:
Yes
Yes
Yes
No

-----Explanation-----
In the first example, Devu can't apply any operation. So the final element in the array will be 1 itself. 

In the second example,
Devu can replace 1 and 3 with any of the numbers among 1, 2, 3. Hence final element of the array could be 1, 2 or 3.

Source: codechef | Difficulty: EASY
Tags: Constructive algorithms

Mathematics

Ad-hoc


Solutions:
(N, Q) = map(int, input().split())
A = list(map(int, input().split()))
mn = min(A)
mx = max(A)
for i in range(Q):
	print('Yes' if mn <= int(input()) <= mx else 'No')


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
x = max(a)
y = min(a)
for i in range(q):
	p = int(input())
	if p <= x and p >= y:
		print('Yes')
	else:
		print('No')


def query(ar, k, a, b):
	return 'Yes' if k <= a and k >= b else 'No'

def __starting_point():
	(n, t) = map(int, input().split())
	ar = list(map(int, input().split()))
	(large, small) = (max(ar), min(ar))
	for i in range(t):
		k = int(input())
		print(query(ar, k, large, small))
__starting_point()


(a, b) = map(int, input().split())
arr = list(map(int, input().split()))
(c, d) = (min(arr), max(arr))
for n in range(b):
	f = int(input())
	if f >= c and f <= d:
		print('Yes')
	else:
		print('No')


(N, Q) = map(int, input().split())
A = list(map(int, input().split()))
c = min(A)
d = max(A)
for i in range(Q):
	t = int(input())
	if c <= t <= d:
		print('Yes')
	else:
		print('No')


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
x = max(a)
y = min(a)
for it in range(q):
	t = int(input())
	if t <= x and t >= y:
		print('Yes')
	else:
		print('No')


import collections
from collections import defaultdict
import math
(n, z) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
p = min(a)
q = max(a)
for i in range(z):
	if p <= int(input()) <= q:
		print('Yes')
	else:
		print('No')


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
g = min(a)
f = max(a)
for i in range(q):
	t = int(input())
	if g <= t <= f:
		print('Yes')
	else:
		print('No')


(N, Q) = map(int, input().split())
li = list(map(int, input().split()))
mins = min(li)
maxs = max(li)
for i in range(Q):
	a = int(input())
	if a >= mins and a <= maxs:
		print('Yes')
	else:
		print('No')


(n, q) = map(int, input().split())
l = [int(x) for x in input().split()]
mn = min(l)
mx = max(l)
for i in range(q):
	k = int(input())
	if k <= mx and k >= mn:
		print('Yes')
	else:
		print('No')


(n, m) = map(int, input().split())
a = [int(x) for x in input().split()]
mh = min(a)
mp = max(a)
for i in range(m):
	b = int(input())
	if b <= mp and b >= mh:
		print('Yes')
	else:
		print('No')


(n, q) = map(int, input().split())
l = list(map(int, input().split()))
m = max(l)
n = min(l)
while q != 0:
	r = int(input())
	if m >= r and n <= r:
		print('Yes')
	else:
		print('No')
	q -= 1


(n, q) = map(int, input().split())
array = list(map(int, input().split()))
array.sort()
for _ in range(q):
	t = int(input())
	if t >= array[0] and t <= array[n - 1]:
		print('Yes')
	else:
		print('No')


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
x = min(a)
y = max(a)
for _ in range(q):
	q1 = int(input())
	if q1 <= y and q1 >= x:
		print('Yes')
	else:
		print('No')


(n, q) = map(int, input().split())
l = list(map(int, input().split()))
mini = min(l)
maxi = max(l)
for i in range(q):
	m = int(input())
	if m <= maxi and m >= mini:
		print('Yes')
	else:
		print('No')


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
m = min(a)
l = max(a)
for p in range(q):
	c = int(input())
	if m <= c <= l:
		print('Yes')
	else:
		print('No')


(n, q) = list(map(int, input().split()))
numbers = list(map(int, input().split()))
b = min(numbers)
c = max(numbers)
for _ in range(q):
	t = int(input())
	if t >= b and t <= c:
		print('Yes')
	else:
		print('No')


(n, m) = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
p = min(t)
q = max(t)
for i in range(m):
	r = int(input())
	if r >= p and r <= q:
		print('Yes')
	else:
		print('No')


(n, q) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = min(a)
c = max(a)
for i in range(q):
	t = int(input())
	if t >= b and t <= c:
		print('Yes')
	else:
		print('No')


(lenght, q) = map(int, input().split())
inputarr = list(map(int, input().split()))
maxval = max(inputarr)
minval = min(inputarr)
for i in range(q):
	check = int(input())
	if check >= minval and check <= maxval:
		print('Yes')
	else:
		print('No')


(a, b) = map(int, input().split())
l = list(map(int, input().split()))
x = min(l)
y = max(l)
for i in range(b):
	z = int(input())
	if x <= z and y >= z:
		print('Yes')
	else:
		print('No')


(n, q) = map(int, input().split())
li = list(map(int, input().split()))
s = min(li)
b = max(li)
for _ in range(q):
	num = int(input())
	if s <= num <= b:
		print('Yes')
	else:
		print('No')


(a, b) = map(int, input().split())
arr = list(map(int, input().split()))
(c, d) = (min(arr), max(arr))
for i in range(b):
	e = int(input())
	if e >= c and e <= d:
		print('Yes')
	else:
		print('No')


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
h = min(a)
s = max(a)
for i in range(q):
	k = int(input())
	if h <= k <= s:
		print('Yes')
	else:
		print('No')


def chk(a, q, n):
	l = a[0]
	m = a[n - 1]
	if q >= l and q <= m:
		return 'Yes'
	return 'No'

def main():
	(n, q) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	A.sort()
	while q > 0:
		q -= 1
		ques = int(input())
		print(chk(A, ques, n))

def __starting_point():
	main()
__starting_point()


(n, q) = map(int, input().split())
l = list(map(int, input().split()))
(a, b) = (min(l), max(l))
for _ in range(q):
	t = int(input())
	if a <= t and t <= b:
		print('Yes')
	else:
		print('No')


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
for i in range(q):
	t = int(input())
	if t <= a[-1] and t >= a[0]:
		print('Yes')
	else:
		print('No')


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
c = min(a)
k = max(a)
while q != 0:
	t = int(input())
	if c <= t and k >= t:
		print('Yes')
	else:
		print('No')
	q = q - 1


(n, q) = map(int, input().split())
a = [int(x) for x in input().split()]
u = min(a)
v = max(a)
for _ in range(q):
	t = int(input())
	if t <= v and t >= u:
		print('Yes')
	else:
		print('No')


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
u = min(a)
v = max(a)
for i in range(q):
	t = int(input())
	if t <= v and t >= u:
		print('Yes')
	else:
		print('No')


(N, Q) = map(int, input().split())
l = list(map(int, input().split()))
s = min(l)
b = max(l)
for _ in range(Q):
	number = int(input())
	if b >= number >= s:
		print('Yes')
	else:
		print('No')


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
cmin = min(c)
cmax = max(c)
for i in range(b):
	d = int(input())
	if cmin <= d <= cmax:
		print('Yes')
	else:
		print('No')


(n, q) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
amin = min(a)
amax = max(a)
for i in range(q):
	print('Yes') if amin <= int(input()) <= amax else print('No')


(n, q) = list(map(int, input().split()))
l = list(map(int, input().split()))
mi = min(l)
mx = max(l)
for i in range(q):
	m = int(input())
	if m <= mx and m >= mi:
		print('Yes')
	else:
		print('No')


(n, m) = [int(x) for x in input().split()]
k = [int(x) for x in input().split()]
a = min(k)
b = max(k)
for i in range(m):
	c = int(input())
	if c >= a and c <= b:
		print('Yes')
	else:
		print('No')


(N, Q) = map(int, input().split())
L = list(map(int, input().split()))
x = min(L)
y = max(L)
for i in range(Q):
	z = int(input())
	if x <= z and y >= z:
		print('Yes')
	else:
		print('No')


(n, q) = map(int, input().split())
l = sorted(list(map(int, input().split())))
for i in range(q):
	a = int(input())
	if l[0] <= a <= l[-1]:
		print('Yes')
	else:
		print('No')


(n, q) = map(int, input().split())
arr = [int(x) for x in input().split()]
a = min(arr)
b = max(arr)
for _ in range(q):
	x = int(input())
	if x >= a and x <= b:
		print('Yes')
	else:
		print('No')


(n, m) = map(int, input().split())
l = sorted(list(map(int, input().split())))
for j in range(m):
	k = int(input())
	if l[0] <= k and k <= l[-1]:
		print('Yes')
	else:
		print('No')


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
start = a[0]
end = a[n - 1]
for i in range(q):
	num = int(input())
	if start <= num <= end:
		print('Yes')
	else:
		print('No')


(N, Q) = map(int, input().split())
A = list(map(int, input().split()))[:N]
l = min(A)
m = max(A)
for x in range(Q):
	o = int(input())
	if l <= o and m >= o:
		print('Yes')
	else:
		print('No')


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
mi = min(a)
ma = max(a)
for _ in range(q):
	t = int(input())
	if t >= mi and t <= ma:
		print('Yes')
	else:
		print('No')


(N, Q) = map(int, input().split())
A = list(map(int, input().split()))
x = min(A)
y = max(A)
for i in range(Q):
	t = int(input())
	if x <= t <= y:
		print('Yes')
	else:
		print('No')


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
mina = min(a)
maxa = max(a)
for i in range(q):
	t = int(input())
	if mina <= t and maxa >= t:
		print('Yes')
	else:
		print('No')


try:
	(N, Q) = map(int, input().split())
	L = list(map(int, input().split()))
	(MIN, MAX) = (min(L), max(L))
	while Q > 0:
		Q -= 1
		q = int(input())
		if MIN <= q <= MAX:
			print('Yes')
		else:
			print('No')
except:
	pass


(n, q) = map(int, input().split())
arr = list(map(int, input().split()))
mn = min(arr)
mx = max(arr)
for i in range(q):
	t = int(input())
	if mn <= t <= mx:
		print('Yes')
	else:
		print('No')


(n, q) = list(map(int, input().split()))
a = list(map(int, input().split()))
l = []
for j in range(1, max(a) + 1):
	if min(a) <= j and j <= max(a):
		l.append(j)
for i in range(q):
	t = int(input())
	if t in l:
		print('Yes')
	else:
		print('No')


(n, q) = list(map(int, input().split()))
a1 = list(map(int, input().split()))
b = min(a1)
c = max(a1)
for i in range(q):
	s = int(input())
	if s >= b and s <= c:
		print('Yes')
	else:
		print('No')


(n, q) = map(int, input().split())
content = [int(x) for x in input().split()]
b = min(content)
c = max(content)
for _ in range(q):
	d = int(input())
	if d >= b and d <= c:
		print('Yes')
	else:
		print('No')


(n, q) = map(int, input().split())
arr = list(map(int, input().split()))
maximum = max(arr)
minimum = min(arr)
for i in range(q):
	t = int(input())
	if t >= minimum and t <= maximum:
		print('Yes')
	else:
		print('No')


(n, q) = map(int, input().split())
k = [int(x) for x in input().split()]
a1 = min(k)
a2 = max(k)
for i in range(q):
	t = int(input())
	if t <= a2 and t >= a1:
		print('Yes')
	else:
		print('No')


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
l = min(a)
h = max(a)
for i in range(k):
	q = int(input())
	if q >= l and q <= h:
		print('Yes')
	else:
		print('No')


(n, q) = map(int, input().split())
l = list(map(int, input().split()))
m = min(l)
ma = max(l)
for i in range(q):
	t = int(input())
	if t >= m and t <= ma:
		print('Yes')
	else:
		print('No')


(n, q) = list(map(int, input().split()))
a = [int(i) for i in input().split()]
p = min(a)
z = max(a)
for i in range(q):
	t = int(input())
	if p <= t <= z:
		print('Yes')
	else:
		print('No')


(n, q) = map(int, input().split())
arr = list(map(int, input().split()))
mini = min(arr)
maxi = max(arr)
for i in range(q):
	a = int(input())
	if a <= maxi and a >= mini:
		print('Yes')
	else:
		print('No')


(n, q) = list(map(int, input().split()))
l = list(map(int, input().split()))
a = max(l)
b = min(l)
for i in range(q):
	y = int(input())
	if y >= b and y <= a:
		print('Yes')
	else:
		print('No')


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
mx = max(a)
mn = min(a)
for _ in range(q):
	t = int(input())
	if t >= mn and t <= mx:
		print('Yes')
	else:
		print('No')


(N, Q) = map(int, input().split())
A = list(map(int, input().split()))
mi = min(A)
ma = max(A)
for i in range(Q):
	n = int(input())
	print('Yes') if mi <= n <= ma else print('No')