Cod sursa(job #964576)

Utilizator RusuAlexeiRusu Alexei RusuAlexei Data 21 iunie 2013 15:30:42
Problema Statistici de ordine Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 0.95 kb
program statistici_de_ordine;
  var n,z,i:longint;
      a:array [1..3000000] of longint;
      bufin:array[1..100000] of byte;

procedure select(l,r: longint);
      var
         i,j,x,y: longint;
      begin
         i:=l;
         j:=r;
         x:=a[(l+r) div 2];
         repeat
           while a[i]<x do
            inc(i);
           while x<a[j] do
            dec(j);
           if not(i>j) then
             begin
                y:=a[i];
                a[i]:=a[j];
                a[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if z<=j then if l<j then select(l,j);
         if z>=i then if r>i then select(i,r);

      end;

begin
  assign(input,'sdo.in');
  reset(input);
  settextbuf(input,bufin);
  assign(output,'sdo.out');
  rewrite(output);

  readln(n,z);

 { for i:= 1 to n do read(a[i]);

  select(1,n);   }
  writeln(a[z]);
  close(output);
end.