找到了一个pascal AC的程序。
program rq604missile;
type
ret=record
x,y,dis:longint;
end;
var
x1,y1,x2,y2,n,i,ans,r:longint;
a:array[1..100000]of ret;
procedure qsort(head,tail:longint);
var
i,j:longint;
x:ret;
begin
i:=head;j:=tail;x:=a[i];
while i<j do
begin
while(i<j)and(x.dis>=a[j].dis) do j:=j-1;
a[i]:=a[j];
while(i<j)and(x.dis<=a[i].dis) do i:=i+1;
a[j]:=a[i];
end;
a[i]:=x;
if head<i-1 then qsort(head,i-1);
if i+1<tail then qsort(i+1,tail);
end;
function dist(a,b,c,d:longint):longint;
begin
dist:=sqr(a-c)+sqr(b-d);
end;
procedure init;
begin
readln(x1,y1,x2,y2);
readln(n);
for i:=1 to n do
begin
with a[i] do
begin
readln(x,y);
dis:=dist(x,y,x1,y1);
end;
end;
qsort(1,n);
r:=0;
end;
procedure work;
begin
ans:=a[1].dis;
for i:=2 to n do
begin
with a[i-1] do
begin
if r<dist(x2,y2,x,y) then r:=dist(x2,y2,x,y);
if ans>a[i].dis+r then ans:=a[i].dis+r;
end;
end;
end;
begin
init;
work;
writeln(ans);
close(input);
end.