Pagini recente » Cod sursa (job #2241028) | Cod sursa (job #136341) | Cod sursa (job #2075206) | Cod sursa (job #2370454) | Cod sursa (job #81210)
Cod sursa(job #81210)
var a,b,poz : array[0..200000] of integer;
n,i,j,semn,x,y,max,s : longint;
f,g : text;
begin
assign(f,'buline.in'); reset(f);
assign(g,'buline.out'); rewrite(g);
readln(f,n);
for i:=1 to n do begin
read(f,a[i]);
read(f,semn);
if semn=1 then a[i]:=-a[i];
end;
for i:=1 to n do begin
if a[i]>b[i-1]+a[i] then
begin
b[i]:=a[i];
if b[i]>max then begin max:=b[i];y:=i; end;
poz[i]:=i;
end
else
begin
b[i]:=b[i-1]+a[i];
if b[i]>max then begin max:=b[i];y:=i; end;
poz[i]:=poz[i-1];
end;
end;
for i:=1 to n do s:=s-a[i];
s:=s+max;
writeln(g,s,' ',y+1,' ',n-(y+1)+poz[y]);
close(g);
end.