var
a:array[1..10000]of longint;
procedure qsort(l,r:longint);
var i,j,x,t:longint;
begin
i:=l;j:=r;x:=a[(l+r)>>1];
repeat
while a[i]<x do inc(i);
while a[j]>x do dec(j);
if i<=j then begin
t:=a[i];a[i]:=a[j];a[j]:=t;
inc(i);dec(j);end;
until i>j;
if i<r then qsort(i,r);
if j>l then qsort(l,j);
end;
function prime(m:longint):string;
var i:longint;
begin
if m<2 then exit('NO');
for i:=2 to trunc(sqrt(m)) do if m mod i=0 then exit('NO');
exit('YES');
end;
var
n,k,i,m:longint;
begin
read(n,k);
for i:=1 to n do read(a[i]);
qsort(1,n);
m:=a[n-k+1]-a[k];
writeln(prime(m));write(m);
end.
tyvj 1001 第K极值
最新推荐文章于 2017-10-24 17:56:00 发布