Pagini recente » Cod sursa (job #2678815) | Cod sursa (job #1631359) | Cod sursa (job #372052) | Cod sursa (job #2769224) | Cod sursa (job #39771)
Cod sursa(job #39771)
const maxn = 200001;
var f:text;
n,i,ml,mp,t,max:longint;
sol:longint;
a,c,c1,d:array[1..maxn]of longint;
procedure readdata;
var x,y:longint;
begin
assign(f,'buline.in');
reset(f);
readln(f,n);
for i:=1 to n do
begin
readln(f,x,y);
if y=0 then y:=-1;
a[i]:=x*y;
t:=t+a[i];
end;
close(f);
end;
procedure solve;
begin
c[1]:=a[1];
max:=0;
for i:=2 to n do
begin
c[i]:=a[i];
d[i]:=1;
if c[i-1]>0 then
begin
c[i]:=c[i]+c[i-1];
d[i]:=d[i]+d[i-1];
end;
if c[i]>max then
begin
max:=c[i];
mp:=i-d[i]+1;
ml:=d[i];
end;
end;
sol:=c[n];
c1[1]:=a[1]+sol;
for i:=2 to n-d[n] do
begin
c1[i]:=a[i];
if c1[i-1]>0 then
begin
c1[i]:=c1[i]+c1[i-1];
end;
if c1[i]<0 then break;
if c1[i]>max then
begin
max:=c1[i];
mp:=n-d[n]+1;
ml:=d[n]+i;
end;
end;
end;
procedure writedata;
begin
assign(f,'buline.out');
rewrite(f);
writeln(f,max,' ',mp,' ',ml);
close(f);
end;
begin
readdata;
solve;
writedata;
end.