-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp.py
More file actions
27 lines (24 loc) · 630 Bytes
/
p.py
File metadata and controls
27 lines (24 loc) · 630 Bytes
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
"""
Given an array A of size N and an integer K , check if there exist any pair of index i,j such that Ai+Aj=K and i≠j
"""
def main():
for _ in range(int(input())):
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
i = 0
j = n-1
flag = 0
while i<j:
if a[i]+a[j]==k:
print('Yes')
flag = 1
break
elif (a[i]+a[j])>k:
j-=1
else:
i+=1
if not(flag):
print('No')
if __name__=="__main__":
main()