Cod sursa(job #775310)

Utilizator t.g.g.tt.g.g.t t.g.g.t Data 7 august 2012 19:34:09
Problema Buline Scor 30
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.56 kb
var a:array[1..399999]of integer; s,p,l,n,se,i,j:longint;
bufer:array[1..1 shl 18]of char;
begin
assign(input,'buline.in'); reset(input); settextbuf(input,bufer);
readln(n);
for i:=1 to n do begin readln(a[i],se); if se=0 then a[i]:=-a[i] end;
for i:=(n+1) to ((2*n)-1) do a[i]:=a[i-n];
s:=0; l:=0;p:=0;
for i:=1 to n do
  begin
  se:=0;
    for j:=i to (i+n-1) do
      begin
        se:=se+a[j];
        if se>s then begin s:=se; p:=i; l:=j-i+1; end;
      end;
  end;
assign(output,'buline.out'); rewrite(output);
write(s,' ',p,' ',l);
close(output);
end.