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 1126. Magnetic Storms

Why this program WA? Gime me a test, please.
Posted by Andrey Popyk (popyk@ief.tup.km.ua) 25 Sep 2002 16:36
CONST DimQ = 25007;

TYPE Elem = record
              Num:longint;
              Time:integer;
            end;
VAR Queue:Array[1..DimQ] of Elem;
    LenQ:integer;
    MyEl:Elem;

PROCEDURE Add(El:Elem);
var T:integer;
begin
  inc(LenQ);
  T:=LenQ;
  while (T<>1) and (Queue[T div 2].Num < El.Num) do
  begin
    Queue[T]:=Queue[T div 2];
    T:=T div 2;
  end;
  Queue[T]:=El;
end;

PROCEDURE DelTop;
var El:Elem;
    T:integer;
begin
  El:=Queue[LenQ]; dec(LenQ);
  T:=1;
  while (2*T+1<=LenQ) and (Queue[2*T+1].Num > El.Num) or
        (2*T<=LenQ) and (Queue[2*T].Num > El.Num) do
  begin
    if (2*T+1<=LenQ) and (Queue[2*T+1].Num > Queue[2*T].Num)
      then begin Queue[T]:=Queue[2*T+1]; T:=2*T+1 end
      else begin Queue[T]:=Queue[2*T]; T:=2*T end;
  end;
  Queue[T]:=El;
end;

PROCEDURE Solve;
var All,M:integer;
begin
  All:=0;
  readln(M);
  repeat
    readln(MyEl.Num);
    if MyEl.Num = -1 then break;
    inc(All); MyEl.Time:=All;
    Add(MyEl);
    if All>=M then begin
                     while Queue[1].Time<=All-M do DelTop;
                     writeln(Queue[1].Num);
                   end;
  until false;
end;

BEGIN
{  assign(INPUT,'1126.dat'); reset(INPUT);}
  Solve;
END.
And why this program CRASH???
Posted by Andrey Popyk (popyk@ief.tup.km.ua) 25 Sep 2002 16:39
VAR A:Array[1..25007] of longint;
    M,Max,K,i,j:longint;
BEGIN
  readln(M);
  repeat
    inc(K);
    readln(A[K]);
    if A[k]=-1 then break;
  until false;
  dec(K);
  for i:=1 to K-M+1 do
  begin
    Max:=i;
    for j:=i to i+M-1 do
      if A[j]>A[Max] then Max:=j;
    writeln(A[Max]);
  end;
END.