Pagini recente » Cod sursa (job #109778) | Cod sursa (job #3240981) | Cod sursa (job #2217054) | Cod sursa (job #2734571) | Cod sursa (job #775310)
Cod sursa(job #775310)
var a: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;
for i:=1 to n do
begin
se:=0;
for j:=i to (i+n-1) do
begin
se:=se+a[j];
if se>s then begin s:=se; p:=i; l:=j-i+1; end;
end;
end;
assign(output,'buline.out'); rewrite(output);
write(s,' ',p,' ',l);
close(output);
end.