Pagini recente » Cod sursa (job #1739521) | Cod sursa (job #2624060) | Cod sursa (job #896886) | Cod sursa (job #1780336) | Cod sursa (job #25417)
Cod sursa(job #25417)
var v,x:array[1..400010]of longint;
t,i,smax,sc,p,l,n,b,c,pmax,lmax,max,poz,lung: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;
for t:=1 to n do
if v[t]>0 then begin
sc:=v[t];
smax:=v[t];
p:=t;l:=1;
for i:=t+1 to n+t-1 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;
if smax>max then
begin
max:=smax;
poz:=pmax;
lung:=lmax;
end;
end;
writeln(max,' ',poz,' ',lung);
close(input);close(output);
end.