ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1306. Sequence Median

snake Help me!!!! I have MLE!! Why [3] // Problem 1306. Sequence Median 24 Jun 2004 22:18
{$APPTYPE CONSOLE}
var
m:array[0..250000] of longword;
n,size,i:longint;
res:extended;
newel:longword;
child:longint;
t:longword;

procedure downHeap(k,n:longint);
begin
newel:=m[k];
while(k<=n) do begin
child:=2*k+1;
if(child<n)and(m[child]<m[child+1]) then inc(child);
if(newel>=m[child])or(child>n) then break;
m[k]:=m[child];
k:=child;
end;
m[k]:=newel;
end;

procedure HeapSort;
begin
for i:=(size-1) div 2 downto 0 do downHeap(i,size-1);

i:=size;
while(i>0) do begin
dec(i);
t:=m[i];
m[i]:=m[0];
m[0]:=t;
downHeap(0,i-1);
end;
end;

begin
readln(size);
for i:=0 to size-1 do readln(m[i]);
HeapSort;
n:=size;
if n mod 2=1 then begin res:=m[((n+1)div 2)-1]; write(res:0:1) end else begin
res:=m[n div 2-1];
res:=res+m[n div 2];
res:=res/2;
write(res:0:1);
end;
end.
Saturn (HUS) Re: Help me!!!! I have MLE!! Why [2] // Problem 1306. Sequence Median 25 Jun 2004 13:23
Your program used 1000K(data) + 80K (program)->memory limit
snake Re: Help me!!!! I have MLE!! Why [1] // Problem 1306. Sequence Median 28 Jun 2004 20:51
What I should do to get AC
Yuanming YU, Frank heap sort // Problem 1306. Sequence Median 7 Jul 2004 09:32