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

Help me! I made heap sort, but I have WA on test 1!!!
Posted by snake 19 Jun 2004 18:56
{$APPTYPE CONSOLE}
{$N+}
const
maxn=250000;
var
m:array[0..maxn] of longint;
size,i:longint;
res:extended;

procedure downHeap(k,n:longint);
var newel,child: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;
var t,i:longint;
begin
for i:=(size div 2) downto 0  do downHeap(i,size-1);

i:=size;
while(i>=1) 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;
if size mod 2=0 then res:=(m[size div 2]+m[size div 2 -1])/2 else res:=m[size div 2 -1];
write(res:0:1);
end.
ft...
Posted by Future 29 Aug 2004 10:00
faint....I submitted a wrong problem....now it's wa5

Edited by author 29.08.2004 10:03