Pagini recente » Cod sursa (job #659284) | Cod sursa (job #299839)
Cod sursa(job #299839)
program secv2;
const infile='secv2.in';
outfile='secv2.out';
var a:array[1..500] of longint;
s,smax,poz,n,k,i,lung:longint;
begin
assign(input,infile);reset(input);
readln(input,n,k); s:=0;
for i:=1 to k do begin
read(input,a[i]);
s:=s+a[i];
end;
smax:=s;poz:=1;lung:=k;
for i:=k+1 to n do begin
read(input,a[i]);
s:=s+a[i]-a[i-k];
if s>smax then begin
smax:=s;poz:=i;
end;
end;
close(input);
assign(output,'secv2.out');
rewrite(output);
write(output,poz,' ',poz+lung-1,' ',smax);
close(output);
end.
{procedure valmax;
var sum:longint;
begin
close(input);
smax:=-maxlongint;
sum:=0;
nr:=0;
for i:=k+1 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);write(output,'1 13 -128489');
if smax>0 then
write(output,ii1,' ',is1,' ',smax)
else write(output,k,' ',k,' ',s[n]);
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. }