Pagini recente » Cod sursa (job #471596) | Cod sursa (job #778278) | Cod sursa (job #2784132) | Cod sursa (job #2539496) | Cod sursa (job #29473)
Cod sursa(job #29473)
var a:array[0..200000]of integer; x,i,n:longint; sf,ic,pz,sc,sm:longint; f1,f2:text;
begin
assign(f1,'buline.in');
reset(f1);
assign(f2,'buline.out');
rewrite(f2);
read(f1,n);
for i:=1 to n do begin
read(f1,a[i]);
read(f1,x);
if x=0 then a[i]:=a[i]*(-1);
end;
a[0]:=a[n];
sm:=a[1];
sc:=sm;
pz:=1;
ic:=1;
sf:=1;
for i:=2 to 2*n do begin
if sc<0 then begin sc:=a[i mod n]; pz:=i; end
else sc:=sc+a[i mod n];
if sc>sm then begin
sm:=sc;
ic:=pz;
sf:=i;
end;
if i mod n=ic-1 then sc:=0;
end;
write(f2,sm,' ',ic,' ',sf-ic+1);
close(f1);
close(f2);
end.