Pagini recente » Cod sursa (job #622512) | Cod sursa (job #2624175) | Cod sursa (job #1221671) | Cod sursa (job #1776218) | Cod sursa (job #332616)
Cod sursa(job #332616)
uses math;
var t:text;
x:array[0..400000] of longint;
a,b,n,i,j,ma,l,lung,dela,lungl,delal:longint;
begin
assign(t,'buline.in'); reset(t);
readln(t,n);
l:=0; ma:=-555555; lung:=0;
for i:=1 to 2*n-1 do
begin
if i<=n then
begin
read(t,x[i],a);
if a=0 then x[i]:=-x[i];
x[i+n]:=x[i];
end;
//ma:=max(ma+x[i],x[i]);
if (x[i]>ma+x[i]) then begin dela:=i; ma:=x[i]; lung:=1; end
else begin inc(lung); ma:=x[i]+ma; end;
if lung>n then begin ma:=ma-x[dela]; inc(dela); lung:=n; end;
if x[i]>ma then begin dela:=i; ma:=x[i]; lung:=1; end;
if ma>l then begin l:=ma; delal:=dela; lungl:=lung; end;
end;
close(t); assign(t,'buline.out'); rewrite(t);
delal:=delal mod n;
if delal=0 then delal:=1;
l:=0;
for i:=delal to delal+lungl-1 do
l:=l+x[i];
writeln(t,l,' ',delal,' ',lungl);
close(t);
end.