Pagini recente » Cod sursa (job #2412076) | Cod sursa (job #2874520) | Cod sursa (job #1152400) | Cod sursa (job #1757381) | Cod sursa (job #3911)
Cod sursa(job #3911)
{infoarena - secventa 2 - arhiva}
const max = 50001;
var a,sum:array[1..max] of longint;
n,k,dr,st,suma:longint;
procedure citire;
var i:longint;
begin
assign(input,'secv2.in'); reset(input);
readln(n,k);
for i:=1 to n do begin read(a[i]); a[i]:=a[i]; end;
close(input);
end;
procedure calc;
var i,smax,pozmax:longint;
begin
smax:=-maxint*10000;
sum[1]:=a[1];
for i:=2 to n do
begin
sum[i]:=sum[i-1]+a[i];
if (sum[i] > smax) and (i >=k) then begin
smax:=sum[i];
pozmax:=i;
end;
end;
dr:=pozmax;
sum[pozmax]:=a[pozmax];
smax:=-maxint*1000;
for i:=pozmax-1 downto 1 do
begin
sum[i]:=sum[i+1] + a[i];
if (sum[i] > smax ) and (dr - i +1 >= k ) then
begin
smax:=sum[i];
pozmax:=i;
end;
end;
st:=pozmax;
suma:=0;
for i:=st to dr do suma:=suma+a[i];
end;
begin
citire;
assign(output,'secv2.out'); rewrite(output);
calc;
writeln(st,' ',dr,' ',suma);
close(output);
end.