Pagini recente » Cod sursa (job #2679059) | Cod sursa (job #3213425) | Cod sursa (job #2059825) | Cod sursa (job #44753) | Cod sursa (job #299350)
Cod sursa(job #299350)
program secv2;
const infile='secv2.in';
outfile='secv2.out';
var s:array[1..50000] of longint;
smax,i,k,n,a,ii1,nr,is1:longint;
procedure valmax;
var sum:longint;
begin
smax:=-maxlongint;
sum:=0;
nr:=0;
for i:=k to n do begin
sum:=sum+s[i]-s[i-1];
if sum>=0 then
inc(nr);
if sum>smax then begin
ii1:=i-nr+1;
smax:=sum;
is1:=i;
end;
if sum<0 then begin sum:=0; nr:=0; end;
end;
assign(output,outfile);
rewrite(output);
if smax>0 then
write(output,ii1,' ',is1,' ',smax)
else write(output,ii1-1,' ',is1,' ',smax);
close(output);
end;
begin
assign(input,infile);
reset(input);
readln(input,n,k);
read(input,s[1]);
for i:=2 to n do begin
read(input,nr);
s[i]:=nr+s[i-1];
end;
valmax;
end.