Min Value

You are given an array of N integers and q queries. In each query you are given an integer value x. …

Click here to read the complete problem statement.


If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

A,B=map(int,input().split())
M=sorted(list(map(int,input().split())))
for i in range(B):
n=int(input())
p=99999999999
for k in M:
z=abs(k-n)
if z<p:
p=z
if z>p:
break
print(p)
I tried using PyPy 3.6 to solve this problem, could anyone help me to make my code more efficient?