Pagini recente » Cod sursa (job #476921) | Cod sursa (job #2337280) | Cod sursa (job #1249937) | Cod sursa (job #2154780) | Cod sursa (job #331636)
Cod sursa(job #331636)
var buline:array[0..400000]of -10000..10000;
suma,s:int64;
n:integer;
li,lf,li1,i:longint;
t:text;
y:0..1;
begin
assign(t,'buline.in'); reset(t);
readln(t,n);
for i:=1 to n do begin
readln(t,buline[i],y);
if y=0 then buline[i]:=-buline[i];
end;
for i:=n+1 to n*2-1 do buline[i]:=buline[i-n];
close(t);
suma:=buline[1];
s:=buline[1];
li1:=1;
li:=1;
lf:=1;
for i:=2 to n*2-1 do begin
if s<0 then begin s:=buline[i]; li1:=i; end
else s:=s+buline[i];
if suma<s then begin
suma:=s;
li:=li1;
lf:=i;
end;
end;
assign(t,'buline.out'); rewrite(t);
if li>n then begin li:=li-n; lf:=lf-n; end;
writeln(t,suma,' ',li,' ',lf-li+1);
close(t);
end.