Pagini recente » Cod sursa (job #2453027) | Cod sursa (job #3205226) | Cod sursa (job #1865484) | Cod sursa (job #3033290) | Cod sursa (job #25039)
Cod sursa(job #25039)
var f,g:text;
smax1,a,sc:array[0..200000]of integer;
i,n,x,y,poz,smax,l: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,x,y);
if y=0 then a[i]:=-x
else a[i]:=x;
end;
sc[1]:=a[1];poz:=1;
smax:=a[1];x:=1;y:=1;
for i:=2 to n do
begin
if sc[i-1]<0 then begin
sc[i]:=a[i];
poz:=i;
end
else sc[i]:=sc[i-1]+a[i];
if sc[i]>smax then begin
smax:=sc[i];
x:=poz;
y:=i;
end;
end;
smax1[0]:=smax;
for i:=1 to x-1 do
smax1[i]:=smax1[i-1]+a[i];
for i:=1 to x-1 do
if smax1[i]>smax then begin
smax:=smax1[i];
y:=i;
end;
if y<x then l:=n-x+1+y
else l:=y-x+1;
writeln(g,smax,' ',x,' ',l);
close(f);
close(g);
end.