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 i got WA. I've compared my sol with others, they nearly the same!!
Posted by noname 16 Jun 2003 21:09
Here's my code. my email: klux_13@sina.com

program magnetic_storms;

var n,m:integer;
    a:array[1..25000] of longint;
    h:array[0..100000] of integer;

procedure init;
  var d:longint;
  begin
    fillchar(a,sizeof(a),0);
    readln(m); n:=0;
    readln(d);
    while d<>-1 do
      begin
        inc(n);
        a[n]:=d;
        readln(d);
      end;
  end;

procedure work;
  var i,max:longint;
  begin
    fillchar(h,sizeof(h),0); h[0]:=1;
    max:=0;
    for i:=1 to m do
      begin
        inc(h[a[i]]);
        if a[i]>max then max:=a[i];
      end;
    writeln(max);
    for i:=m+1 to n do
      begin
        inc(h[a[i]]);
        dec(h[a[i-m]]);
        if a[i]>max then max:=a[i]
        else if h[max]=0 then
                begin
                  while h[max]=0 do dec(max);
                end;
        writeln(max);
      end;
  end;

begin
assign(input,'1126.in'); reset(input);
  init;
  work;
end.