Pagini recente » Cod sursa (job #545588) | Cod sursa (job #230778) | Cod sursa (job #2614825) | Cod sursa (job #1560572) | Cod sursa (job #25191)
Cod sursa(job #25191)
var v,x:array[1..400010]of longint;
i,smax,sc,p,l,n,b,c,pmax,lmax:longint;
begin
assign(input,'buline.in');reset(input);
assign(output,'buline.out');rewrite(output);
readln(n);
for i:=1 to n do
begin
readln(b,c);
if c=1 then
v[i]:=b
else
v[i]:=-b;
v[n+i]:=v[i];
end;
sc:=v[1];
smax:=v[1];
p:=1;l:=1;
for i:=2 to 2*n do
begin
if l<n then
if sc+v[i]>v[i]
then begin
sc:=sc+v[i];
inc(l);
end
else
begin
sc:=v[i];
p:=i;
l:=1;
end;
if sc+v[i]<=v[i] then
begin
sc:=v[i];
p:=i;
l:=1;
end;
if sc>smax then
begin
smax:=sc;
pmax:=p;
lmax:=l;
end;
end;
writeln(smax,' ',pmax,' ',lmax);
close(input);close(output);
end.