Cod sursa(job #34293)

Utilizator raduzerRadu Zernoveanu raduzer Data 20 martie 2007 16:39:25
Problema Buline Scor 80
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.94 kb
var a,s,t:array[1..200010]of longint;
    n,i,j,c,max,poz,l,z:longint;
begin
     assign(input,'buline.in');
     reset(input);
     assign(output,'buline.out');
     rewrite(output);
     readln(n);
     for i:=1 to n do
     begin
          readln(a[i],c);
          if c=0 then a[i]:=0-a[i];
     end;
     s[1]:=a[1];
     t[1]:=s[1];
     for i:=2 to n do
     begin
          s[i]:=s[i-1]+a[i];
          if s[i]>t[i-1] then
          begin
               t[i]:=s[i];
          end
          else t[i]:=t[i-1];
     end;
     max:=t[n];
     for i:=2 to n do
          if t[i-1]+s[n]-s[i-1]>max then
          begin
               max:=t[i-1]+s[n]-s[i-1];
               poz:=i;
          end;
     l:=0;
     i:=poz-1;
     z:=0;
     while z<max do
     begin
          i:=i+1;
          if i>n then i:=1;
          l:=l+1;
          z:=z+a[i];
     end;
     writeln(max,' ',poz,' ',l);
close(output);
end.