Pagini recente » Cod sursa (job #716055) | Cod sursa (job #630955) | Cod sursa (job #3235798) | Cod sursa (job #2467051) | Cod sursa (job #775313)
Cod sursa(job #775313)
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.