Cod sursa(job #5296)
Utilizator | Ionescu Victor vanila0406 | Data | 11 ianuarie 2007 16:37:06 |
---|---|---|---|
Problema | Secventa 2 | Scor | 0 |
Compilator | fpc | Status | done |
Runda | Arhiva de probleme | Marime | 1.34 kb |
0program secv2;
var f,g:text;
n,k:longint;
v,aux:array[1..50001] of qword;
procedure iofile;
var i:longint;
begin
assign(f,'secv2.in');
reset(f);
assign(g,'secv2.out');
rewrite(g);
readln(f,n,k);
read(f,v[1]);
aux[1]:=v[1];
for i:=2 to n do
begin
read(f,v[i]);
aux[i]:=v[i]+aux[i-1];
end;
close(f);
end;
procedure prel;
var poz,p,u,i,sum,max:longint;
begin
p:=1;
u:=k;
poz:=1;
sum:=aux[k];
max:=-maxlongint;
for i:=k+1 to n do
begin
sum:=sum+v[i];
if sum<aux[i]-aux[i-k] then
begin
sum:=aux[i]-aux[i-k];
poz:=i-k+1;
end;
if sum>max then
begin
max:=sum;
p:=poz;
u:=i;
end;
end;
writeln(g,p,' ',u,' ',max);
close(g);
end;
begin
iofile;
prel;
end.