Pagini recente » Cod sursa (job #1881400) | Cod sursa (job #2856272) | Cod sursa (job #2316026) | Cod sursa (job #1966291) | Cod sursa (job #25047)
Cod sursa(job #25047)
var f,g:text;
n,i,s_cr,s,l,x,l_cr,pz_cr,p:integer;
a:array[1..30000] of integer;
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,a[i],x);
if x=0 then a[i]:=a[i]*(-1);
end;
for i:=1 to n-1 do a[i+n]:=a[i];
pz_cr:=1; s_cr:=0; l:=0; l_cr:=1;
for i:=1 to 2*n-1 do
begin
if l_cr<=n then
begin
s_cr:=s_cr+a[i];
if s_cr>s then
begin
s:=s_cr;
p:=pz_cr;
L:=l_cr;
end;
if s_cr=s then
begin
if p>pz_cr then
begin
p:=pz_cr;
L:=l_cr;
end;
if p=pz_cr then
if L>l_cr then L:=l_cr;
end;
inc(l_cr);
end;
if s_cr<0 then
begin
s_cr:=0;
pz_cr:=i+1;
l_cr:=1;
end;
if l_cr>n then
begin
s_cr:=0;
pz_cr:=i;
l_cr:=1;
end;
end;
write(g,s,' ',p,' ',L);
close(g);
end.