var n,m,i,j:longint;a:array[1..1000000] of int64;
s,min:int64;
begin
readln(n,m);min:=high(int64);
for i:=1 to n do read(a[i]);
for i:=1 to n-m+1 do
begin
s:=0;
for j:=i to i+m-1 do s:=s+a[i];
if s<min then min:=s;
end;
writeln(min);
readln;
end.
bạn cho một cái text đi bạn
const fi='tongmin.inp';
fo='tongmin.out';
var a:array[1..100]of integer;
n,m,i,j,k:byte;
s,min:integer;
f1,f2:text;
begin
assign(f1,fi); reset(f1);
assign(f2,fo); rewrite(f2);
readln(f1,n,m);
for i:=1 to n do
begin
read(f1,a[i]);
end;
{---------------xuat--------------------}
for i:=1 to n do write(f2,a[i]:4);
{---------------------------------------}
writeln(f2);
k:=1;
min:=0;
for i:=1 to m do min:=min+a[i];
for i:=2 to n-m+1 do
begin
s:=0;
for j:=i to i+m-1 do
s:=s+a[j];
if s<min then begin
min:=s;
k:=i;
end;
end;
writeln(f2,'day con co tong nho nhat la: ');
for i:=k to k+m-1 do write(f2,a[i]:4);
close(f1);
close(f2);
end.
uses crt;
var a:array[1..100]of integer;
n,m,i,j,k:byte;
s,min:integer;
begin
clrscr;
write('nhap chieu dai day so:'); readln(n);
for i:=1 to n do
begin
write('a[',i,']='); readln(a[i]);
end;
{---------------xuat--------------------}
for i:=1 to n do write(a[i]:4);
{---------------------------------------}
writeln;
write('nhap do dai day con:'); readln(m);
k:=1;
min:=0;
for i:=1 to m do min:=min+a[i];
for i:=2 to n-m+1 do
begin
s:=0;
for j:=i to i+m-1 do
s:=s+a[j];
if s<min then begin
min:=s;
k:=i;
end;
end;
writeln('day con co tong nho nhat la: ');
for i:=k to k+m-1 do write(a[i]:4);
readln;
end.