Cod sursa(job #629116)

Utilizator ctlin04UAIC.VlasCatalin ctlin04 Data 2 noiembrie 2011 17:38:29
Problema Statistici de ordine Scor 50
Compilator fpc Status done
Runda gc_practice Marime 0.75 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:longint;
 begin
  i:=l; j:=r;
   k:=a[(l+r) div 2];
 repeat
  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;
 until i>=j;
 if (i<=t) or (j>=t) then
  if l<j then sort(l,j);
   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.