Cod sursa(job #25191)

Utilizator CezarMocanCezar Mocan CezarMocan Data 4 martie 2007 11:18:19
Problema Buline Scor 20
Compilator fpc Status done
Runda preONI 2007, Runda 3, Clasa a 9-a si gimnaziu Marime 1.07 kb
var v,x:array[1..400010]of longint;
    i,smax,sc,p,l,n,b,c,pmax,lmax:longint;
begin
assign(input,'buline.in');reset(input);
assign(output,'buline.out');rewrite(output);
readln(n);
for i:=1 to n do
        begin
        readln(b,c);
        if c=1 then
                v[i]:=b
        else
                v[i]:=-b;
        v[n+i]:=v[i];
        end;
sc:=v[1];
smax:=v[1];
p:=1;l:=1;
for i:=2 to 2*n do
        begin
        if l<n then
        if sc+v[i]>v[i]
                then begin
                sc:=sc+v[i];
                inc(l);
                end
        else
                begin
                sc:=v[i];
                p:=i;
                l:=1;
                end;
        if sc+v[i]<=v[i] then
                begin
                sc:=v[i];
                p:=i;
                l:=1;
                end;
        if sc>smax then
                begin
                smax:=sc;
                pmax:=p;
                lmax:=l;
                end;
        end;
writeln(smax,' ',pmax,' ',lmax);
close(input);close(output);
end.