Cod sursa(job #26093)

Utilizator maria_pparcalabescu maria daniela maria_p Data 5 martie 2007 10:19:18
Problema Buline Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.01 kb
var f,g:text;
    smax1,a,sc:array[0..200000]of integer;
    i,n,x,y,poz,smax,l:longint;

begin
assign(f,'buline.in');reset(f);
assign(g,'buline.out');rewrite(g);
readln(f,n);
for i:=1 to n do
    begin
    readln(f,x,y);
    if y=0 then a[i]:=-x
           else a[i]:=x;
    end;
sc[1]:=a[1];poz:=1;
smax:=a[1];x:=1;y:=1;
for i:=2 to n do
    begin
    if sc[i-1]<0 then begin
                 sc[i]:=a[i];
                 poz:=i;
                 end
            else sc[i]:=sc[i-1]+a[i];
    if sc[i]>smax then begin
                    smax:=sc[i];
                    x:=poz;
                    y:=i;
                    end;
    end;
if y=n then begin
smax1[0]:=smax;
for i:=1 to x-1 do
    smax1[i]:=smax1[i-1]+a[i];
for i:=1 to x-1 do
    if smax1[i]>smax then begin
                          smax:=smax1[i];
                          y:=i;
                          end;
end;
if y<x then l:=n-x+1+y
       else l:=y-x+1;
writeln(g,smax,' ',x,' ',l);
close(f);
close(g);
end.