Cod sursa(job #25237)

Utilizator marius21Petcu Marius marius21 Data 4 martie 2007 11:33:53
Problema Buline Scor 30
Compilator fpc Status done
Runda preONI 2007, Runda 3, Clasa a 9-a si gimnaziu Marime 0.88 kb
type cerc=record
nr:int64;
poz,lengt:longint;
end;
var a:array[1..200000] of cerc;
smax,s:int64;
m,ocol,col,nr1,l,p,lmax,pmax,i,j,n:longint;
f,g:text;
begin
assign(f,'buline.in');
assign(g,'buline.out');
reset(f);
read(f,n);
a[1].lengt:=1;
a[1].poz:=1;
m:=1;
read(f,nr1,col);
if col=0 then nr1:=-nr1;
ocol:=col;
a[1].nr:=nr1;
for i:=2 to n do begin
read(f,nr1,col);
if col=0 then nr1:=-nr1;
smax:=smax+nr1;
if col=ocol then begin
inc(a[m].lengt);
a[m].nr:=a[m].nr+nr1;
end
else begin
ocol:=col;
inc(m);
a[m].lengt:=1;
a[m].poz:=i;
a[m].nr:=nr1;
end;
end;
lmax:=m;
pmax:=1;
close(f);
for i:=1 to m do begin
s:=0;
l:=0;
for j:=0 to m-2 do begin
p:=(i+j) mod m;
if p=0 then p:=m;
s:=s+a[p].nr;
l:=l+a[p].lengt;
if s>smax then begin
smax:=s;
pmax:=a[i].poz;
lmax:=l;
end;
end;
end;
rewrite(g);
writeln(g,smax,' ',pmax,' ',lmax);
close(g);
end.