Pagini recente » onis-2016/solutii-runda-1 | captainbobulous | Cod sursa (job #1315874) | Cod sursa (job #2094512) | Cod sursa (job #282047)
Cod sursa(job #282047)
var a:array[1..500000] of int64;
f,g:Text;
aux:int64;
n,i:longint;
procedure sort(l,r:longint);
var i,j:longint;
pivot:int64;
begin
i:=l; j:=r; pivot:=a[random(r-l)+l];
repeat
while a[i]<pivot do i:=i+1;
while pivot<a[j] do j:=j-1;
if i<=j then begin
aux:=a[i];
a[i]:=a[j];
a[j]:=aux;
i:=i+1; j:=j-1;
end;
until i>j;
if i<r then sort(i,r);
if l<j then sort(l,j);
end;
begin
randomize;
assign(f,'algsort.in'); reset(f);
assign(g,'algsort.out'); rewrite(g);
read(f,n);
for i:=1 to n do
read(f,a[i]);
sort(1,n);
for i:=1 to n do
write(g,a[i],' ');
close(f); close(g);
end.