You are given a one-dimensional array of N integers. Find in the array the maximum length of a sequence

You are given a one-dimensional array of N integers. Find in the array the maximum length of a sequence of contiguous elements, each of which is greater than or equal to the previous one.

The program searches for a non-decreasing sequence of maximum length in an array of 20 elements. If there are several sequences, the first one is marked.

program length;

var a: array [1..20] of integer;
max, max_i, min_i, k: integer;
begin
randomize;
writeln ();
for i: integer: = 1 to 20 do write (i: 5);
writeln ();
for i: integer: = 1 to 20 do
begin
a [i]: = (random (100) + 1);
write (a [i]: 5)
end;
max: = 1;
k: = 1;
for i: integer: = 1 to 19 do
begin
if a [i] <= a [i + 1] then k: = k + 1;
if k> max then
begin
max: = k;
max_i: = i + 1
end
else k: = 1
end;
writeln ();
writeln (” * ((max_i – max) * 5 + 2), ‘-‘ * (max * 5 – 2));
writeln (‘Maximum sequence length -‘, max)
end.



One of the components of a person's success in our time is receiving modern high-quality education, mastering the knowledge, skills and abilities necessary for life in society. A person today needs to study almost all his life, mastering everything new and new, acquiring the necessary professional qualities.