Pagini recente » Cod sursa (job #369024) | Cod sursa (job #1113623) | Cod sursa (job #2918366) | Cod sursa (job #2860191) | Cod sursa (job #123651)
Cod sursa(job #123651)
var f,g:text;
a:array[1..400000] of integer;
n,ic,pc,max,x,sc,l,i,y: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,a[i],x);
if x=0 then a[i]:=-a[i];
end;
for i:=1 to n-1 do a[i+n]:=a[i];
y:=n;
n:=n+n-1;
max:=a[1];
sc:=a[1];
ic:=1; pc:=1;
for i:=2 to n do
begin
if i-pc+1>n then sc:=sc-a[pc];
if sc>0 then sc:=sc+a[i]
else
begin
sc:=a[i];
pc:=i;
end;
if sc=max then
begin
if ic mod y>pc mod y then
begin
ic:=pc;
l:=i-pc+1;
end
else if ic mod y=pc mod y then
if i-pc+1<l then l:=i-pc+1;
end;
if sc>max then
begin
ic:=pc;
l:=i-pc+1;
max:=sc;
end;
end;
writeln(g,max,' ',ic,' ',l);
close(g);
end.