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 1037. Memory Management

Why WA? Who can give me some test suits
Posted by Big Guava 28 Mar 2002 13:26
var
    a:array[1..30000,0..2] of integer;
    i,k,t,last,head,minfree,n:integer;
    s:string;

begin
//    assign(input,'input1037.txt');reset(input);
  //  assign(output,'output1037.txt');rewrite(output);
    last:=1; head:=1; minfree:=1; a[1,0]:=65000;
    while not eof(input) do begin
        readln(s);
        if pos('+',s)<>0 then begin
            val(copy(s,1,pos('+',s)-1),t,k);
            if (t-a[head,0])<600 then begin
                writeln(minfree);
                a[minfree,2]:=last;
                a[last,1]:=minfree;
                a[minfree,0]:=t;
                last:=minfree;
                inc(minfree);
            end else begin
                writeln(head);
                i:=head;
                head:=a[i,1];
                a[last,1]:=i;
                a[i,2]:=last;
                last:=i;
                a[i,0]:=t;
            end;
        end else begin
            // Request
            val(copy(s,1,pos('.',s)-1),t,k);
            delete(s,1,pos('.',s));
            while s[1]=' ' do delete(s,1,1);
            val(s,n,k);
            if (n>=minfree) or (t-a[n,0]>=600) then begin
                writeln('-');
            end else begin
                writeln('+');
                a[n,0]:=t;
                if n=last then continue;
                if n=head then begin
                    head:=a[head,1];
                    a[last,1]:=n;
                    a[n,2]:=last;
                    last:=n;
                end else begin
                    i:=a[n,2];
                    a[i,1]:=a[n,1];
                    a[a[n,1],2]:=i;
                    a[last,1]:=n;
                    a[n,2]:=last;
                    last:=n;
                end;
            end;
        end;
    end;
end.