Pagini recente » Cod sursa (job #508226) | Cod sursa (job #2411986) | Cod sursa (job #28744)
Cod sursa(job #28744)
const maxn = 400000;
var f:text;
n,i,p,l,ml,mp:longint;
s,max:longint;
a:array[1..maxn]of longint;
procedure readdata;
var x,y:longint;
begin
assign(f,'buline.in');
reset(f);
readln(f,n);
for i:=1 to n do
begin
readln(f,x,y);
if y=0 then y:=-1;
a[i]:=x*y;
a[i+n]:=x*y;
end;
close(f);
end;
procedure solve;
begin
i:=2;
s:=a[1];
p:=1;
l:=1;
while i<=2*n do
begin
if (s>=0) then
begin
if l<n then
begin
s:=s+a[i];
inc(l);
end
else
begin
s:=s-a[i-l];
if s>=0 then
begin
s:=s+a[i];
inc(p);
if p>n then p:=p-n;
end
else
begin
s:=a[i];
p:=i;
if p>n then p:=p-n;
l:=1;
end;
end;
end
else
begin
s:=a[i];
p:=i;
if p>n then p:=p-n;
l:=1;
end;
if s>max then
begin
max:=s;
mp:=p;
if mp>n then mp:=mp-n;
ml:=l;
end;
inc(i);
end;
end;
procedure writedata;
begin
assign(f,'buline.out');
rewrite(f);
writeln(f,max,' ',mp,' ',ml);
close(f);
end;
begin
readdata;
solve;
writedata;
end.