Cod sursa(job #25417)

Utilizator CezarMocanCezar Mocan CezarMocan Data 4 martie 2007 12:32:22
Problema Buline Scor 30
Compilator fpc Status done
Runda preONI 2007, Runda 3, Clasa a 9-a si gimnaziu Marime 1.24 kb
var v,x:array[1..400010]of longint;
    t,i,smax,sc,p,l,n,b,c,pmax,lmax,max,poz,lung: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;
for t:=1 to n do
if v[t]>0 then begin
sc:=v[t];
smax:=v[t];
p:=t;l:=1;
for i:=t+1 to n+t-1 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;
if smax>max then
        begin
        max:=smax;
        poz:=pmax;
        lung:=lmax;
        end;
end;
writeln(max,' ',poz,' ',lung);
close(input);close(output);
end.