pascal编程题目,大师解答一下,最好用最简洁的方法,做上批注。

2024-11-22 15:20:50
推荐回答(1个)
回答1:

var
n,k:integer;
a:array[1..1000] of integer;
s:array[1..1000] of longint;
i,j:integer;
max:longint;
begin
readln(n,k);
for i:=1 to n do read(a[i]);
for i:=1 to n do s[i]:=0;
for i:=1 to n-k+1 do for j:=1 to k do s[i]:=s[i]+a[i+j-1];
max:=s[1];
for i:=2 to n-k+1 do if s[i]>max then max:=s[i];
writeln(max);
end.