Cod sursa(job #629137)

Utilizator ctlin04UAIC.VlasCatalin ctlin04 Data 2 noiembrie 2011 18:12:46
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,b2:array [1..1 shl 17] 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');
 settextbuf(fi,b1);
  settextbuf(fo,b2);
 reset(fi); rewrite(fo);
 readln(fi,n,t);
  for i:=1 to n do read(fi,a[i]);
 sort(1,n);
 write(fo,a[t]);
 close(fo);
end.