Pagini recente » Cod sursa (job #2156337) | Cod sursa (job #2782712) | Cod sursa (job #250552) | Cod sursa (job #2381521) | Cod sursa (job #25794)
Cod sursa(job #25794)
var a,b:array[1..200010]of longint;
n,i,j,s,p,l,max,q,m,x,z,t,y: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
q:=1;
if b[i]=1 then s:=a[i]
else s:=-a[i];
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.