Cod sursa(job #775313)

Utilizator t.g.g.tt.g.g.t t.g.g.t Data 7 august 2012 19:46:30
Problema Buline Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.74 kb
var a,b,c:array[1..399999]of integer; s,p,l,n,se,i,j:longint;
bufer:array[1..1 shl 18]of char;
begin
assign(input,'buline.in'); reset(input); settextbuf(input,bufer);
readln(n);
for i:=1 to n do begin readln(a[i],se); if se=0 then a[i]:=-a[i] end;
for i:=(n+1) to ((2*n)-1) do a[i]:=a[i-n];
s:=0; l:=0;p:=0; b[1]:=a[1];c[1]:=1;
for i:=2 to ((2*n)-1) do
  begin
   if b[i-1]>0 then
     begin
       b[i]:=b[i-1]+a[i];
       c[i]:=c[i-1]
     end else
       if b[i-1]<0 then
         begin
           b[i]:=a[i];
           c[i]:=i;
         end;
  end;
s:=-2000000001;
for i:=1 to ((2*n)-1) do if b[i]>s then begin s:=b[i]; p:=c[i]; l:=i-p+1 end;
assign(output,'buline.out'); rewrite(output);
write(s,' ',p,' ',l);
close(output);
end.