Cod sursa(job #25074)

Utilizator raduzerRadu Zernoveanu raduzer Data 4 martie 2007 10:24:47
Problema Buline Scor 30
Compilator fpc Status done
Runda preONI 2007, Runda 3, Clasa a 9-a si gimnaziu Marime 1.03 kb
var a,b:array[1..100000]of longint;
    n,i,j,s,p,l,max,q: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],b[i]);
     end;
     max:=0;
     for i:=1 to n do
     begin
          if b[i]=1 then s:=a[i]
                    else s:=-a[i];
          q:=1;
          if s>max then
               begin
                    max:=s;
                    p:=i;
                    l:=q;
               end;
          j:=i+1;
          if j>n then j:=1;
          while j<>i do
          begin
               if b[j]=1 then s:=s+a[j]
                         else s:=s-a[j];
               q:=q+1;
               if s>max then
               begin
                    max:=s;
                    p:=i;
                    l:=q;
               end;
               j:=j+1;
               if j>n then j:=1;
          end;
     end;
     writeln(max,' ',p,' ',l);
close(output);
end.