Pagini recente » Cod sursa (job #520479) | Cod sursa (job #2934011) | Cod sursa (job #2342407) | Cod sursa (job #826125) | Cod sursa (job #34292)
Cod sursa(job #34292)
var a,b:array[1..100000]of longint;
n,i,j,s,p,l,max,q:longint;
begin
assign(input,'buline.in');
reset(input);
assign(output,'buline.out');
rewrite(output);
readln(n);
for i:=1 to n do
begin
readln(a[i],b[i]);
end;
max:=0;
for i:=1 to n do
begin
if b[i]=1 then s:=a[i]
else s:=-a[i];
q:=1;
if s>max then
begin
max:=s;
p:=i;
l:=q;
end;
j:=i+1;
if j>n then j:=1;
while j<>i do
begin
if b[j]=1 then s:=s+a[j]
else s:=s-a[j];
q:=q+1;
if s>max then
begin
max:=s;
p:=i;
l:=q;
end;
j:=j+1;
if j>n then j:=1;
end;
end;
writeln(max,' ',p,' ',l);
close(output);
end.