Min Value

You are given an array of N integers and q queries. In each query you are given an integer value x. For each x you have to choose a value from the given array. Let, this value be y. Now your task is to find the minimum value of z. Where,


This is a companion discussion topic for the original entry at https://toph.co/p/min-value

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?