Cod sursa(job #629135)

Utilizator ctlin04UAIC.VlasCatalin ctlin04 Data 2 noiembrie 2011 18:10:25
Problema Statistici de ordine Scor 50
Compilator fpc Status done
Runda gc_practice Marime 0.76 kb
Program st;
 var a:array [1..3000000] of longint;
   b1:array [1..1 shl 15] of char;
   i,n,t:longint;
   fi,fo:text;
procedure sort(l,r:longint);
 var k,i,j,y,x:longint;
 begin
  i:=l; j:=r;
   k:=a[random(r-l)+l];
 while i<j do begin
   while a[i]<k do inc(I);
    while a[j]>k do dec(j);
  if i<=j then
              begin
               y:=a[i];
                a[i]:=a[j];
                  a[j]:=y;
                     inc(i); dec(j);
              end;
   end;
 if t<i then begin if l<j then sort(l,j); end
 else
   if i<r then sort(i,r);
 end;
begin
 assign(fi,'sdo.in');
  assign(fo,'sdo.out');
 reset(fi); rewrite(fo);
 settextbuf(fi,b1);
 readln(fi,n,t);
  for i:=1 to n do read(fi,a[i]);
 sort(1,n);
 write(fo,a[t]);
 close(fo);
end.