Cod sursa(job #332616)

Utilizator andrey932Andrei andrey932 Data 18 iulie 2009 23:51:26
Problema Buline Scor 20
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.87 kb
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.