-
Notifications
You must be signed in to change notification settings - Fork 0
/
1461D.py
52 lines (41 loc) · 841 Bytes
/
1461D.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#######puzzleVerma#######
import sys
import math
mod = 10**9+7
LI=lambda:[int(k) for k in input().split()]
input = lambda: sys.stdin.readline().rstrip()
IN=lambda:int(input())
S=lambda:input()
r=range
from bisect import *
def split(l,r,a,sl):
mid=(a[l]+a[r])//2
mid=bisect(a,mid)
sl+=[d[mid-1]-d[l-1]]
if (mid-1)!=r:
split(l,mid-1,a,sl)
sl+=[d[r]-d[mid-1]]
if mid!=l and mid<=r:
split(mid,r,a,sl)
for t in r(IN()):
n,q=LI()
a=LI()
a.sort()
sm=0
d=dict()
d[-1]=0
for i in range(n):
sm+=a[i]
d[i]=sm
sl=[sm]
split(0,n-1,a,sl)
sl.sort()
for i in r(q):
s=IN()
ans=bisect(sl,s)
if ans==0:
print("NO")
elif s==sl[ans-1]:
print('YES')
else:
print('NO')