Тема: И снова йа
![]() | ![]() |
Чота опять не правильно

при N=20 [4 5 6 8 9 7 2 3 5 8 9 4 1 5 2 8 2 9 7 6] должно быть 34, а получаем 31прост строгий знак сменил на не строгий Гг.
теперь при N=5 [5,5,5,5,5] ответ 20)
program sweet;
var N, n1, j, i, W, max11, max22, max1, max2: integer;
R: array [1..100] of integer;
begin
repeat
begin
write('write N ');
readln(N);
end;
until (N<100) and (N>0);
for i:=1 to N do
begin
repeat
begin
write ('R',i,' = ');
readln(R[i]);
end;
until (R[i]>0) and (R[i]<1000);
end;
if N = 1 then W:= R[1]
else if N = 2 then W:= R[1] + R[2]
else if N = 3 then W:= R[1] + R[2] + R[3]
else if N = 4 then W:= R[1] + R[2] + R[3] + R[4]
else
begin
if R[1]>R[2] then
begin
max1:= R[1];
max11:=R[2];
end
else
begin
max1:= R[2];
max11:=R[1];
end;
j:=2;
for i:=3 to N do
begin
if (R[i] >= max1) and (i<>j) then
begin
max2:=max1;
max22:=max11;
max1:=R[i];
j:= i+1;
if i < N then
begin
if R[i+1]>R[i-1] then
max11:=R[i+1]
else
max11:=R[i-1];
end
else
max11:=R[i-1];
end;
end;
W:= max1 + max11 + max2 + max22;
end;
writeln('W = ',w);
end.