Pagini recente » Cod sursa (job #679844) | Cod sursa (job #2225371) | Cod sursa (job #937303) | Cod sursa (job #1164347) | Cod sursa (job #123677)
Cod sursa(job #123677)
var t,s:array[1..400000] of longint;
a:array[1..200000] of longint;
pc,l,i,j,x,n,max:integer;
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
readln(f,a[i],x);
if x=0 then a[i]:=-a[i];
end;
for i:=1 to n-1 do a[i+n]:=a[i];
s[1]:=a[1]; t[1]:=s[1];
for i:=2 to n+n-1 do
begin
s[i]:=s[i-1]+a[i];
if s[i]>t[i-1] then t[i]:=s[i]
else t[i]:=t[i-1];
end;
for i:=2 to n do
begin
if max=t[i-1]+s[n]-s[i-1] then
if i<pc then pc:=i;
if max<t[i-1]+s[n]-s[i-1] then
begin
max:=t[i-1]+s[n]-s[i-1];
pc:=i;
j:=i;
repeat inc(j)
until s[j]-s[i-1]=max;
l:=j-i+1;
end;
end;
writeln(g,max,' ',pc,' ',l);
close(g);
end.